Skip to content

Commit 6d13893

Browse files
committed
dbft: correct the improper usage of interface
1 parent 70be52c commit 6d13893

File tree

2 files changed

+29
-29
lines changed

2 files changed

+29
-29
lines changed

consensus/dbft/dbft.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ type DBFT struct {
211211
finished chan struct{}
212212

213213
// various native contract APIs that dBFT uses.
214-
backend *ethapi.Backend
214+
backend ethapi.Backend
215215
txAPI *ethapi.TransactionAPI
216216
// staticPool is a legacy pool instance for decrypted transaction verification,
217217
// which is initialized once per height at postBlock callback. It should be reset
@@ -430,7 +430,7 @@ func (c *DBFT) getValidatorsCb(txs ...dbft.Transaction[common.Hash]) []dbft.Publ
430430
// block's validators, thus should return validators from the current
431431
// epoch without recalculation.
432432
if c.backend != nil {
433-
pKeys, err = (*c.backend).GetValidatorsSorted(&c.lastIndex, nil, nil)
433+
pKeys, err = c.backend.GetValidatorsSorted(&c.lastIndex, nil, nil)
434434
} else {
435435
err = errNotInitializedBackend
436436
}
@@ -1059,7 +1059,7 @@ func (c *DBFT) processPreBlockCb(b dbft.PreBlock[common.Hash]) error {
10591059
for _, preC := range ctx.PreCommitPayloads {
10601060
if preC != nil && preC.ViewNumber() == ctx.ViewNumber {
10611061
if c.backend != nil {
1062-
dkgIndex, err = (*c.backend).GetDKGIndex(blockNum, int(preC.ValidatorIndex()))
1062+
dkgIndex, err = c.backend.GetDKGIndex(blockNum, int(preC.ValidatorIndex()))
10631063
} else {
10641064
err = errNotInitializedBackend
10651065
}
@@ -1408,7 +1408,7 @@ func (c *DBFT) getBlockWitness(pub *tpke.PublicKey, block *Block) ([]byte, error
14081408
var dkgIndex int
14091409
blockNum := block.header.Number.Uint64() - 1
14101410
if c.backend != nil {
1411-
dkgIndex, err = (*c.backend).GetDKGIndex(blockNum, i)
1411+
dkgIndex, err = c.backend.GetDKGIndex(blockNum, i)
14121412
} else {
14131413
err = errNotInitializedBackend
14141414
}
@@ -1444,7 +1444,7 @@ func (c *DBFT) getBlockWitness(pub *tpke.PublicKey, block *Block) ([]byte, error
14441444
// WithEthAPIBackend initializes Eth API backend and transaction API for
14451445
// proper consensus module work.
14461446
func (c *DBFT) WithEthAPIBackend(b ethapi.Backend) {
1447-
c.backend = &b
1447+
c.backend = b
14481448
c.txAPI = ethapi.NewTransactionAPI(b, new(ethapi.AddrLocker))
14491449
}
14501450

@@ -2405,7 +2405,7 @@ func (c *DBFT) validatePayload(p *Payload) error {
24052405
if c.backend == nil {
24062406
return errNotInitializedBackend
24072407
}
2408-
validators, err := (*c.backend).GetValidatorsSorted(&h, nil, nil)
2408+
validators, err := c.backend.GetValidatorsSorted(&h, nil, nil)
24092409
if err != nil {
24102410
return fmt.Errorf("failed to get next block validators: %w", err)
24112411
}
@@ -2491,7 +2491,7 @@ func (c *DBFT) calcDifficulty(signer common.Address, parent *types.Header) *big.
24912491
if c.backend == nil {
24922492
return nil
24932493
}
2494-
vals, err := (*c.backend).GetValidatorsSorted(&h, nil, nil)
2494+
vals, err := c.backend.GetValidatorsSorted(&h, nil, nil)
24952495
if err != nil {
24962496
return nil
24972497
}
@@ -2712,7 +2712,7 @@ func (c *DBFT) getNextConsensus(h *types.Header, s *state.StateDB) (common.Hash,
27122712
if c.backend == nil {
27132713
log.Crit("Can't calculate next consensus", "err", errNotInitializedBackend)
27142714
}
2715-
nextVals, err := (*c.backend).GetValidatorsSorted(nil, s.Copy(), h)
2715+
nextVals, err := c.backend.GetValidatorsSorted(nil, s.Copy(), h)
27162716
if err != nil {
27172717
log.Crit("Failed to compute next block validators",
27182718
"err", err)

consensus/dbft/dkg.go

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func (s *snapshot) Copy() *snapshot {
7474
}
7575

7676
// init initializes snapshot with the specified startup parameters.
77-
func (s *snapshot) init(api *ethapi.Backend, h *types.Header, state *state.StateDB, height uint64) error {
77+
func (s *snapshot) init(api ethapi.Backend, h *types.Header, state *state.StateDB, height uint64) error {
7878
s.EpochStartHeight = height
7979
round, err := getRoundNumber(api, state, h)
8080
if err != nil {
@@ -555,7 +555,7 @@ func (c *DBFT) loopWatchTaskList() {
555555

556556
var watchTaskList []*task
557557
for range c.loopWatchTaskChan {
558-
currentHeight := (*c.backend).CurrentBlock().Number.Uint64()
558+
currentHeight := c.backend.CurrentBlock().Number.Uint64()
559559
if len(c.appendWatchTaskChan) > 0 {
560560
// Append watchList from appendWatchTaskChan to watchTaskList.
561561
newWatchList := <-c.appendWatchTaskChan
@@ -773,7 +773,7 @@ func (t *taskList) taskReshareRecover(keystore *antimev.KeyStore, receiverMessag
773773
}
774774

775775
// getCurrentConsensus returns an address list of current CNs.
776-
func getCurrentConsensus(backend *ethapi.Backend, state *state.StateDB, header *types.Header) ([]common.Address, error) {
776+
func getCurrentConsensus(backend ethapi.Backend, state *state.StateDB, header *types.Header) ([]common.Address, error) {
777777
var result []common.Address
778778
err := readFromContract(&result, backend, systemcontracts.GovernanceProxyHash, systemcontracts.GovernanceABI, state, header, "getCurrentConsensus")
779779
if err != nil {
@@ -783,7 +783,7 @@ func getCurrentConsensus(backend *ethapi.Backend, state *state.StateDB, header *
783783
}
784784

785785
// getPendingConsensus returns an address list of pending CNs.
786-
func getPendingConsensus(backend *ethapi.Backend, state *state.StateDB, header *types.Header) ([]common.Address, error) {
786+
func getPendingConsensus(backend ethapi.Backend, state *state.StateDB, header *types.Header) ([]common.Address, error) {
787787
var result []common.Address
788788
err := readFromContract(&result, backend, systemcontracts.GovernanceProxyHash, systemcontracts.GovernanceABI, state, header, "getPendingConsensus")
789789
if err != nil {
@@ -793,7 +793,7 @@ func getPendingConsensus(backend *ethapi.Backend, state *state.StateDB, header *
793793
}
794794

795795
// getSharePeriodDuration returns a number of blocks as the duration of each sharing period.
796-
func getSharePeriodDuration(backend *ethapi.Backend, state *state.StateDB, header *types.Header) (uint64, error) {
796+
func getSharePeriodDuration(backend ethapi.Backend, state *state.StateDB, header *types.Header) (uint64, error) {
797797
var result *big.Int
798798
err := readFromContract(&result, backend, systemcontracts.GovernanceProxyHash, systemcontracts.GovernanceABI, state, header, "sharePeriodDuration")
799799
if err != nil {
@@ -803,7 +803,7 @@ func getSharePeriodDuration(backend *ethapi.Backend, state *state.StateDB, heade
803803
}
804804

805805
// getEpochDuration returns a number of blocks as the duration of each governanace epoch.
806-
func getEpochDuration(backend *ethapi.Backend, state *state.StateDB, header *types.Header) (uint64, error) {
806+
func getEpochDuration(backend ethapi.Backend, state *state.StateDB, header *types.Header) (uint64, error) {
807807
var result *big.Int
808808
err := readFromContract(&result, backend, systemcontracts.GovernanceProxyHash, systemcontracts.GovernanceABI, state, header, "epochDuration")
809809
if err != nil {
@@ -813,7 +813,7 @@ func getEpochDuration(backend *ethapi.Backend, state *state.StateDB, header *typ
813813
}
814814

815815
// getCurrentEpochStartHeight returns the block height when the current governanace epoch starts.
816-
func getCurrentEpochStartHeight(backend *ethapi.Backend, state *state.StateDB, header *types.Header) (uint64, error) {
816+
func getCurrentEpochStartHeight(backend ethapi.Backend, state *state.StateDB, header *types.Header) (uint64, error) {
817817
var result *big.Int
818818
err := readFromContract(&result, backend, systemcontracts.GovernanceProxyHash, systemcontracts.GovernanceABI, state, header, "currentEpochStartHeight")
819819
if err != nil {
@@ -823,7 +823,7 @@ func getCurrentEpochStartHeight(backend *ethapi.Backend, state *state.StateDB, h
823823
}
824824

825825
// getMessagePubkeys returns the message keys of input address list.
826-
func getMessagePubkeys(backend *ethapi.Backend, addrs []common.Address, state *state.StateDB, header *types.Header) ([]*ecies.PublicKey, error) {
826+
func getMessagePubkeys(backend ethapi.Backend, addrs []common.Address, state *state.StateDB, header *types.Header) ([]*ecies.PublicKey, error) {
827827
result := make([]*ecies.PublicKey, len(addrs))
828828
for i, addr := range addrs {
829829
pub, err := getMessagePubkey(backend, addr, state, header)
@@ -836,7 +836,7 @@ func getMessagePubkeys(backend *ethapi.Backend, addrs []common.Address, state *s
836836
}
837837

838838
// getMessagePubkey returns the message key of input address.
839-
func getMessagePubkey(backend *ethapi.Backend, addr common.Address, state *state.StateDB, header *types.Header) (*ecies.PublicKey, error) {
839+
func getMessagePubkey(backend ethapi.Backend, addr common.Address, state *state.StateDB, header *types.Header) (*ecies.PublicKey, error) {
840840
var result string
841841
err := readFromContract(&result, backend, systemcontracts.KeyManagementProxyHash, systemcontracts.KeyManagementABIBasic, state, header, "messagePubkeys", addr)
842842
if err != nil {
@@ -854,7 +854,7 @@ func getMessagePubkey(backend *ethapi.Backend, addr common.Address, state *state
854854
}
855855

856856
// getIndexCurrentNeedRecovering returns an array of DKG index that needs recover.
857-
func getIndexCurrentNeedRecovering(backend *ethapi.Backend, state *state.StateDB, header *types.Header) ([]uint64, error) {
857+
func getIndexCurrentNeedRecovering(backend ethapi.Backend, state *state.StateDB, header *types.Header) ([]uint64, error) {
858858
var result []*big.Int
859859
err := readFromContract(&result, backend, systemcontracts.KeyManagementProxyHash, systemcontracts.KeyManagementABIBasic, state, header, "indexCurrentNeedRecovering")
860860
if err != nil {
@@ -868,7 +868,7 @@ func getIndexCurrentNeedRecovering(backend *ethapi.Backend, state *state.StateDB
868868
}
869869

870870
// isShareReady checks if the DKG sharing is 100% uploaded.
871-
func isShareReady(backend *ethapi.Backend, state *state.StateDB, header *types.Header) (bool, error) {
871+
func isShareReady(backend ethapi.Backend, state *state.StateDB, header *types.Header) (bool, error) {
872872
var result bool
873873
err := readFromContract(&result, backend, systemcontracts.KeyManagementProxyHash, systemcontracts.KeyManagementABIBasic, state, header, "isShareReady")
874874
if err != nil {
@@ -878,7 +878,7 @@ func isShareReady(backend *ethapi.Backend, state *state.StateDB, header *types.H
878878
}
879879

880880
// getReshareMsgs gets the reshare messages from specific sender index and round.
881-
func getReshareMsgs(backend *ethapi.Backend, round, index uint64, state *state.StateDB, header *types.Header) ([][]byte, error) {
881+
func getReshareMsgs(backend ethapi.Backend, round, index uint64, state *state.StateDB, header *types.Header) ([][]byte, error) {
882882
var result [][]byte
883883
err := readFromContract(&result, backend, systemcontracts.KeyManagementProxyHash, systemcontracts.KeyManagementABIBasic,
884884
state, header, "getReshareMsgs", big.NewInt(int64(round)), big.NewInt(int64(index)))
@@ -889,7 +889,7 @@ func getReshareMsgs(backend *ethapi.Backend, round, index uint64, state *state.S
889889
}
890890

891891
// getResharePVSS gets the reshare PVSS from specific sender index and round.
892-
func getResharePVSS(backend *ethapi.Backend, round, index uint64, state *state.StateDB, header *types.Header) ([]byte, error) {
892+
func getResharePVSS(backend ethapi.Backend, round, index uint64, state *state.StateDB, header *types.Header) ([]byte, error) {
893893
var result []byte
894894
err := readFromContract(&result, backend, systemcontracts.KeyManagementProxyHash, systemcontracts.KeyManagementABIBasic,
895895
state, header, "rpvsses", big.NewInt(int64(round)), big.NewInt(int64(index)))
@@ -900,7 +900,7 @@ func getResharePVSS(backend *ethapi.Backend, round, index uint64, state *state.S
900900
}
901901

902902
// getShareMsgs gets the share messages from specific sender index and round.
903-
func getShareMsgs(backend *ethapi.Backend, round, index uint64, state *state.StateDB, header *types.Header) ([][]byte, error) {
903+
func getShareMsgs(backend ethapi.Backend, round, index uint64, state *state.StateDB, header *types.Header) ([][]byte, error) {
904904
var result [][]byte
905905
err := readFromContract(&result, backend, systemcontracts.KeyManagementProxyHash, systemcontracts.KeyManagementABIBasic,
906906
state, header, "getShareMsgs", big.NewInt(int64(round)), big.NewInt(int64(index)))
@@ -911,7 +911,7 @@ func getShareMsgs(backend *ethapi.Backend, round, index uint64, state *state.Sta
911911
}
912912

913913
// getSharePVSS gets the share PVSS from specific sender index and round.
914-
func getSharePVSS(backend *ethapi.Backend, round, index uint64, state *state.StateDB, header *types.Header) ([]byte, error) {
914+
func getSharePVSS(backend ethapi.Backend, round, index uint64, state *state.StateDB, header *types.Header) ([]byte, error) {
915915
var result []byte
916916
err := readFromContract(&result, backend, systemcontracts.KeyManagementProxyHash, systemcontracts.KeyManagementABIBasic,
917917
state, header, "spvsses", big.NewInt(int64(round)), big.NewInt(int64(index)))
@@ -922,7 +922,7 @@ func getSharePVSS(backend *ethapi.Backend, round, index uint64, state *state.Sta
922922
}
923923

924924
// getRecoverMsgs gets the recover messages from specific sender index and round, with a receiver index.
925-
func getRecoverMsgs(backend *ethapi.Backend, round, senderIndex, arrIndex uint64, state *state.StateDB, header *types.Header) ([]byte, error) {
925+
func getRecoverMsgs(backend ethapi.Backend, round, senderIndex, arrIndex uint64, state *state.StateDB, header *types.Header) ([]byte, error) {
926926
var result []byte
927927
err := readFromContract(&result, backend, systemcontracts.KeyManagementProxyHash, systemcontracts.KeyManagementABIBasic,
928928
state, header, "recoverMsgs", big.NewInt(int64(round)), big.NewInt(int64(senderIndex)), big.NewInt(int64(arrIndex)))
@@ -933,7 +933,7 @@ func getRecoverMsgs(backend *ethapi.Backend, round, senderIndex, arrIndex uint64
933933
}
934934

935935
// getAggregatedCommitment gets the global aggregated commitment after DKG share.
936-
func getAggregatedCommitment(backend *ethapi.Backend, round uint64, state *state.StateDB, header *types.Header) ([]byte, error) {
936+
func getAggregatedCommitment(backend ethapi.Backend, round uint64, state *state.StateDB, header *types.Header) ([]byte, error) {
937937
var result []byte
938938
err := readFromContract(&result, backend, systemcontracts.KeyManagementProxyHash, systemcontracts.KeyManagementABIBasic,
939939
state, header, "aggregatedCommitments", big.NewInt(int64(round)))
@@ -944,7 +944,7 @@ func getAggregatedCommitment(backend *ethapi.Backend, round uint64, state *state
944944
}
945945

946946
// getRoundNumber gets the DKG round number.
947-
func getRoundNumber(backend *ethapi.Backend, state *state.StateDB, header *types.Header) (uint64, error) {
947+
func getRoundNumber(backend ethapi.Backend, state *state.StateDB, header *types.Header) (uint64, error) {
948948
var result *big.Int
949949
err := readFromContract(&result, backend, systemcontracts.KeyManagementProxyHash, systemcontracts.KeyManagementABIBasic,
950950
state, header, "roundNumber")
@@ -955,7 +955,7 @@ func getRoundNumber(backend *ethapi.Backend, state *state.StateDB, header *types
955955
}
956956

957957
// getZKVersion gets the DKG ZK version
958-
func getZKVersion(backend *ethapi.Backend, state *state.StateDB, header *types.Header) (uint64, error) {
958+
func getZKVersion(backend ethapi.Backend, state *state.StateDB, header *types.Header) (uint64, error) {
959959
var result *big.Int
960960
err := readFromContract(&result, backend, systemcontracts.KeyManagementProxyHash, systemcontracts.KeyManagementABIBasic,
961961
state, header, "ZK_VERSION")
@@ -966,7 +966,7 @@ func getZKVersion(backend *ethapi.Backend, state *state.StateDB, header *types.H
966966
}
967967

968968
// readFromContract calls a contract with ABI-packed inputs.
969-
func readFromContract(res interface{}, backend *ethapi.Backend, contract common.Address, contractAbi abi.ABI, state *state.StateDB, header *types.Header, method string, args ...interface{}) error {
969+
func readFromContract(res interface{}, backend ethapi.Backend, contract common.Address, contractAbi abi.ABI, state *state.StateDB, header *types.Header, method string, args ...interface{}) error {
970970
if backend == nil {
971971
return errNotInitializedBackend
972972
}
@@ -985,7 +985,7 @@ func readFromContract(res interface{}, backend *ethapi.Backend, contract common.
985985
ctx, cancel := context.WithCancel(context.Background())
986986
// Cancel when we are finished consuming integers.
987987
defer cancel()
988-
result, err := ethapi.DoCallAtState(ctx, *backend, txArgs, state, header, nil, nil, 0, 0)
988+
result, err := ethapi.DoCallAtState(ctx, backend, txArgs, state, header, nil, nil, 0, 0)
989989
if err != nil {
990990
return fmt.Errorf("failed to call at state '%s': %v", method, err)
991991
}

0 commit comments

Comments
 (0)