Skip to content

Commit 60c307d

Browse files
committed
dbft: correct the improper usage of interface
1 parent 1d80603 commit 60c307d

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
@@ -217,7 +217,7 @@ type DBFT struct {
217217
dkgTaskWatcherToCloseCh chan struct{}
218218

219219
// various native contract APIs that dBFT uses.
220-
backend *ethapi.Backend
220+
backend ethapi.Backend
221221
txAPI *ethapi.TransactionAPI
222222
// staticPool is a legacy pool instance for decrypted transaction verification,
223223
// which is initialized once per height at postBlock callback. It should be reset
@@ -436,7 +436,7 @@ func (c *DBFT) getValidatorsCb(txs ...dbft.Transaction[common.Hash]) []dbft.Publ
436436
// block's validators, thus should return validators from the current
437437
// epoch without recalculation.
438438
if c.backend != nil {
439-
pKeys, err = (*c.backend).GetValidatorsSorted(&c.lastIndex, nil, nil)
439+
pKeys, err = c.backend.GetValidatorsSorted(&c.lastIndex, nil, nil)
440440
} else {
441441
err = errNotInitializedBackend
442442
}
@@ -1061,7 +1061,7 @@ func (c *DBFT) processPreBlockCb(b dbft.PreBlock[common.Hash]) error {
10611061
for _, preC := range ctx.PreCommitPayloads {
10621062
if preC != nil && preC.ViewNumber() == ctx.ViewNumber {
10631063
if c.backend != nil {
1064-
dkgIndex, err = (*c.backend).GetDKGIndex(blockNum, int(preC.ValidatorIndex()))
1064+
dkgIndex, err = c.backend.GetDKGIndex(blockNum, int(preC.ValidatorIndex()))
10651065
} else {
10661066
err = errNotInitializedBackend
10671067
}
@@ -1413,7 +1413,7 @@ func (c *DBFT) getBlockWitness(pub *tpke.PublicKey, block *Block) ([]byte, error
14131413
var dkgIndex int
14141414
blockNum := block.header.Number.Uint64() - 1
14151415
if c.backend != nil {
1416-
dkgIndex, err = (*c.backend).GetDKGIndex(blockNum, i)
1416+
dkgIndex, err = c.backend.GetDKGIndex(blockNum, i)
14171417
} else {
14181418
err = errNotInitializedBackend
14191419
}
@@ -1449,7 +1449,7 @@ func (c *DBFT) getBlockWitness(pub *tpke.PublicKey, block *Block) ([]byte, error
14491449
// WithEthAPIBackend initializes Eth API backend and transaction API for
14501450
// proper consensus module work.
14511451
func (c *DBFT) WithEthAPIBackend(b ethapi.Backend) {
1452-
c.backend = &b
1452+
c.backend = b
14531453
c.txAPI = ethapi.NewTransactionAPI(b, new(ethapi.AddrLocker))
14541454
}
14551455

@@ -2400,7 +2400,7 @@ func (c *DBFT) validatePayload(p *Payload) error {
24002400
if c.backend == nil {
24012401
return errNotInitializedBackend
24022402
}
2403-
validators, err := (*c.backend).GetValidatorsSorted(&h, nil, nil)
2403+
validators, err := c.backend.GetValidatorsSorted(&h, nil, nil)
24042404
if err != nil {
24052405
return fmt.Errorf("failed to get next block validators: %w", err)
24062406
}
@@ -2487,7 +2487,7 @@ func (c *DBFT) calcDifficulty(signer common.Address, parent *types.Header) *big.
24872487
if c.backend == nil {
24882488
return nil
24892489
}
2490-
vals, err := (*c.backend).GetValidatorsSorted(&h, nil, nil)
2490+
vals, err := c.backend.GetValidatorsSorted(&h, nil, nil)
24912491
if err != nil {
24922492
return nil
24932493
}
@@ -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 {
@@ -603,7 +603,7 @@ watchLoop:
603603
if newWatchList != nil && len(*newWatchList) > 0 {
604604
watchTaskList = append(watchTaskList, *newWatchList...)
605605
}
606-
currentHeight := (*c.backend).CurrentBlock().Number.Uint64()
606+
currentHeight := c.backend.CurrentBlock().Number.Uint64()
607607
log.Info("DKG task watcher", "currentHeight", currentHeight, "watchListLength", len(watchTaskList))
608608

609609
// Loop tasks in watchTaskList.
@@ -806,7 +806,7 @@ func (t *taskList) taskReshareRecover(keystore *antimev.KeyStore, receiverMessag
806806
}
807807

808808
// getCurrentConsensus returns an address list of current CNs.
809-
func getCurrentConsensus(backend *ethapi.Backend, state *state.StateDB, header *types.Header) ([]common.Address, error) {
809+
func getCurrentConsensus(backend ethapi.Backend, state *state.StateDB, header *types.Header) ([]common.Address, error) {
810810
var result []common.Address
811811
err := readFromContract(&result, backend, systemcontracts.GovernanceProxyHash, systemcontracts.GovernanceABI, state, header, "getCurrentConsensus")
812812
if err != nil {
@@ -816,7 +816,7 @@ func getCurrentConsensus(backend *ethapi.Backend, state *state.StateDB, header *
816816
}
817817

818818
// getPendingConsensus returns an address list of pending CNs.
819-
func getPendingConsensus(backend *ethapi.Backend, state *state.StateDB, header *types.Header) ([]common.Address, error) {
819+
func getPendingConsensus(backend ethapi.Backend, state *state.StateDB, header *types.Header) ([]common.Address, error) {
820820
var result []common.Address
821821
err := readFromContract(&result, backend, systemcontracts.GovernanceProxyHash, systemcontracts.GovernanceABI, state, header, "getPendingConsensus")
822822
if err != nil {
@@ -826,7 +826,7 @@ func getPendingConsensus(backend *ethapi.Backend, state *state.StateDB, header *
826826
}
827827

828828
// getSharePeriodDuration returns a number of blocks as the duration of each sharing period.
829-
func getSharePeriodDuration(backend *ethapi.Backend, state *state.StateDB, header *types.Header) (uint64, error) {
829+
func getSharePeriodDuration(backend ethapi.Backend, state *state.StateDB, header *types.Header) (uint64, error) {
830830
var result *big.Int
831831
err := readFromContract(&result, backend, systemcontracts.GovernanceProxyHash, systemcontracts.GovernanceABI, state, header, "sharePeriodDuration")
832832
if err != nil {
@@ -836,7 +836,7 @@ func getSharePeriodDuration(backend *ethapi.Backend, state *state.StateDB, heade
836836
}
837837

838838
// getEpochDuration returns a number of blocks as the duration of each governanace epoch.
839-
func getEpochDuration(backend *ethapi.Backend, state *state.StateDB, header *types.Header) (uint64, error) {
839+
func getEpochDuration(backend ethapi.Backend, state *state.StateDB, header *types.Header) (uint64, error) {
840840
var result *big.Int
841841
err := readFromContract(&result, backend, systemcontracts.GovernanceProxyHash, systemcontracts.GovernanceABI, state, header, "epochDuration")
842842
if err != nil {
@@ -846,7 +846,7 @@ func getEpochDuration(backend *ethapi.Backend, state *state.StateDB, header *typ
846846
}
847847

848848
// getCurrentEpochStartHeight returns the block height when the current governanace epoch starts.
849-
func getCurrentEpochStartHeight(backend *ethapi.Backend, state *state.StateDB, header *types.Header) (uint64, error) {
849+
func getCurrentEpochStartHeight(backend ethapi.Backend, state *state.StateDB, header *types.Header) (uint64, error) {
850850
var result *big.Int
851851
err := readFromContract(&result, backend, systemcontracts.GovernanceProxyHash, systemcontracts.GovernanceABI, state, header, "currentEpochStartHeight")
852852
if err != nil {
@@ -856,7 +856,7 @@ func getCurrentEpochStartHeight(backend *ethapi.Backend, state *state.StateDB, h
856856
}
857857

858858
// getMessagePubkeys returns the message keys of input address list.
859-
func getMessagePubkeys(backend *ethapi.Backend, addrs []common.Address, state *state.StateDB, header *types.Header) ([]*ecies.PublicKey, error) {
859+
func getMessagePubkeys(backend ethapi.Backend, addrs []common.Address, state *state.StateDB, header *types.Header) ([]*ecies.PublicKey, error) {
860860
result := make([]*ecies.PublicKey, len(addrs))
861861
for i, addr := range addrs {
862862
pub, err := getMessagePubkey(backend, addr, state, header)
@@ -869,7 +869,7 @@ func getMessagePubkeys(backend *ethapi.Backend, addrs []common.Address, state *s
869869
}
870870

871871
// getMessagePubkey returns the message key of input address.
872-
func getMessagePubkey(backend *ethapi.Backend, addr common.Address, state *state.StateDB, header *types.Header) (*ecies.PublicKey, error) {
872+
func getMessagePubkey(backend ethapi.Backend, addr common.Address, state *state.StateDB, header *types.Header) (*ecies.PublicKey, error) {
873873
var result string
874874
err := readFromContract(&result, backend, systemcontracts.KeyManagementProxyHash, systemcontracts.KeyManagementABIBasic, state, header, "messagePubkeys", addr)
875875
if err != nil {
@@ -887,7 +887,7 @@ func getMessagePubkey(backend *ethapi.Backend, addr common.Address, state *state
887887
}
888888

889889
// getIndexCurrentNeedRecovering returns an array of DKG index that needs recover.
890-
func getIndexCurrentNeedRecovering(backend *ethapi.Backend, state *state.StateDB, header *types.Header) ([]uint64, error) {
890+
func getIndexCurrentNeedRecovering(backend ethapi.Backend, state *state.StateDB, header *types.Header) ([]uint64, error) {
891891
var result []*big.Int
892892
err := readFromContract(&result, backend, systemcontracts.KeyManagementProxyHash, systemcontracts.KeyManagementABIBasic, state, header, "indexCurrentNeedRecovering")
893893
if err != nil {
@@ -901,7 +901,7 @@ func getIndexCurrentNeedRecovering(backend *ethapi.Backend, state *state.StateDB
901901
}
902902

903903
// isShareReady checks if the DKG sharing is 100% uploaded.
904-
func isShareReady(backend *ethapi.Backend, state *state.StateDB, header *types.Header) (bool, error) {
904+
func isShareReady(backend ethapi.Backend, state *state.StateDB, header *types.Header) (bool, error) {
905905
var result bool
906906
err := readFromContract(&result, backend, systemcontracts.KeyManagementProxyHash, systemcontracts.KeyManagementABIBasic, state, header, "isShareReady")
907907
if err != nil {
@@ -911,7 +911,7 @@ func isShareReady(backend *ethapi.Backend, state *state.StateDB, header *types.H
911911
}
912912

913913
// getReshareMsgs gets the reshare messages from specific sender index and round.
914-
func getReshareMsgs(backend *ethapi.Backend, round, index uint64, state *state.StateDB, header *types.Header) ([][]byte, error) {
914+
func getReshareMsgs(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, "getReshareMsgs", big.NewInt(int64(round)), big.NewInt(int64(index)))
@@ -922,7 +922,7 @@ func getReshareMsgs(backend *ethapi.Backend, round, index uint64, state *state.S
922922
}
923923

924924
// getResharePVSS gets the reshare PVSS from specific sender index and round.
925-
func getResharePVSS(backend *ethapi.Backend, round, index uint64, state *state.StateDB, header *types.Header) ([]byte, error) {
925+
func getResharePVSS(backend ethapi.Backend, round, index 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, "rpvsses", big.NewInt(int64(round)), big.NewInt(int64(index)))
@@ -933,7 +933,7 @@ func getResharePVSS(backend *ethapi.Backend, round, index uint64, state *state.S
933933
}
934934

935935
// getShareMsgs gets the share messages from specific sender index and round.
936-
func getShareMsgs(backend *ethapi.Backend, round, index uint64, state *state.StateDB, header *types.Header) ([][]byte, error) {
936+
func getShareMsgs(backend ethapi.Backend, round, index 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, "getShareMsgs", big.NewInt(int64(round)), big.NewInt(int64(index)))
@@ -944,7 +944,7 @@ func getShareMsgs(backend *ethapi.Backend, round, index uint64, state *state.Sta
944944
}
945945

946946
// getSharePVSS gets the share PVSS from specific sender index and round.
947-
func getSharePVSS(backend *ethapi.Backend, round, index uint64, state *state.StateDB, header *types.Header) ([]byte, error) {
947+
func getSharePVSS(backend ethapi.Backend, round, index uint64, state *state.StateDB, header *types.Header) ([]byte, error) {
948948
var result []byte
949949
err := readFromContract(&result, backend, systemcontracts.KeyManagementProxyHash, systemcontracts.KeyManagementABIBasic,
950950
state, header, "spvsses", big.NewInt(int64(round)), big.NewInt(int64(index)))
@@ -955,7 +955,7 @@ func getSharePVSS(backend *ethapi.Backend, round, index uint64, state *state.Sta
955955
}
956956

957957
// getRecoverMsgs gets the recover messages from specific sender index and round, with a receiver index.
958-
func getRecoverMsgs(backend *ethapi.Backend, round, senderIndex, arrIndex uint64, state *state.StateDB, header *types.Header) ([]byte, error) {
958+
func getRecoverMsgs(backend ethapi.Backend, round, senderIndex, arrIndex uint64, state *state.StateDB, header *types.Header) ([]byte, error) {
959959
var result []byte
960960
err := readFromContract(&result, backend, systemcontracts.KeyManagementProxyHash, systemcontracts.KeyManagementABIBasic,
961961
state, header, "recoverMsgs", big.NewInt(int64(round)), big.NewInt(int64(senderIndex)), big.NewInt(int64(arrIndex)))
@@ -966,7 +966,7 @@ func getRecoverMsgs(backend *ethapi.Backend, round, senderIndex, arrIndex uint64
966966
}
967967

968968
// getAggregatedCommitment gets the global aggregated commitment after DKG share.
969-
func getAggregatedCommitment(backend *ethapi.Backend, round uint64, state *state.StateDB, header *types.Header) ([]byte, error) {
969+
func getAggregatedCommitment(backend ethapi.Backend, round uint64, state *state.StateDB, header *types.Header) ([]byte, error) {
970970
var result []byte
971971
err := readFromContract(&result, backend, systemcontracts.KeyManagementProxyHash, systemcontracts.KeyManagementABIBasic,
972972
state, header, "aggregatedCommitments", big.NewInt(int64(round)))
@@ -977,7 +977,7 @@ func getAggregatedCommitment(backend *ethapi.Backend, round uint64, state *state
977977
}
978978

979979
// getRoundNumber gets the DKG round number.
980-
func getRoundNumber(backend *ethapi.Backend, state *state.StateDB, header *types.Header) (uint64, error) {
980+
func getRoundNumber(backend ethapi.Backend, state *state.StateDB, header *types.Header) (uint64, error) {
981981
var result *big.Int
982982
err := readFromContract(&result, backend, systemcontracts.KeyManagementProxyHash, systemcontracts.KeyManagementABIBasic,
983983
state, header, "roundNumber")
@@ -988,7 +988,7 @@ func getRoundNumber(backend *ethapi.Backend, state *state.StateDB, header *types
988988
}
989989

990990
// getZKVersion gets the DKG ZK version
991-
func getZKVersion(backend *ethapi.Backend, state *state.StateDB, header *types.Header) (uint64, error) {
991+
func getZKVersion(backend ethapi.Backend, state *state.StateDB, header *types.Header) (uint64, error) {
992992
var result *big.Int
993993
err := readFromContract(&result, backend, systemcontracts.KeyManagementProxyHash, systemcontracts.KeyManagementABIBasic,
994994
state, header, "ZK_VERSION")
@@ -999,7 +999,7 @@ func getZKVersion(backend *ethapi.Backend, state *state.StateDB, header *types.H
999999
}
10001000

10011001
// readFromContract calls a contract with ABI-packed inputs.
1002-
func readFromContract(res interface{}, backend *ethapi.Backend, contract common.Address, contractAbi abi.ABI, state *state.StateDB, header *types.Header, method string, args ...interface{}) error {
1002+
func readFromContract(res interface{}, backend ethapi.Backend, contract common.Address, contractAbi abi.ABI, state *state.StateDB, header *types.Header, method string, args ...interface{}) error {
10031003
if backend == nil {
10041004
return errNotInitializedBackend
10051005
}
@@ -1018,7 +1018,7 @@ func readFromContract(res interface{}, backend *ethapi.Backend, contract common.
10181018
ctx, cancel := context.WithCancel(context.Background())
10191019
// Cancel when we are finished consuming integers.
10201020
defer cancel()
1021-
result, err := ethapi.DoCallAtState(ctx, *backend, txArgs, state, header, nil, nil, 0, 0)
1021+
result, err := ethapi.DoCallAtState(ctx, backend, txArgs, state, header, nil, nil, 0, 0)
10221022
if err != nil {
10231023
return fmt.Errorf("failed to call at state '%s': %v", method, err)
10241024
}

0 commit comments

Comments
 (0)