From 761734dbaaf57f16e6fb5c8f213071a859ebd397 Mon Sep 17 00:00:00 2001 From: Akshar Dave Date: Thu, 13 Oct 2022 14:54:44 -0400 Subject: [PATCH 1/8] WIP - forkEpoch config + pass config to ibft consensus --- command/ibft/switch/ibft_switch.go | 9 +++++++++ command/ibft/switch/params.go | 10 ++++++++++ command/ibft/switch/result.go | 2 ++ consensus/consensus.go | 1 + consensus/ibft/hooks.go | 7 +++++++ consensus/ibft/ibft.go | 15 ++++++++++----- consensus/ibft/poa.go | 4 ++++ consensus/ibft/pos.go | 4 ++++ 8 files changed, 47 insertions(+), 5 deletions(-) diff --git a/command/ibft/switch/ibft_switch.go b/command/ibft/switch/ibft_switch.go index 03840692c8..9b7fda5e93 100644 --- a/command/ibft/switch/ibft_switch.go +++ b/command/ibft/switch/ibft_switch.go @@ -5,6 +5,7 @@ import ( "github.com/0xPolygon/polygon-edge/command" "github.com/0xPolygon/polygon-edge/command/helper" + "github.com/0xPolygon/polygon-edge/consensus/ibft" "github.com/spf13/cobra" ) @@ -71,6 +72,14 @@ func setFlags(cmd *cobra.Command) { "", "the custom contract address to use for SC interaction", ) + + cmd.Flags().Uint64Var( + ¶ms.forkEpochSizeRaw, + forkEpochSize, + ibft.DefaultEpochSize, + "Fork level epoch", + ) + } func runPreRun(_ *cobra.Command, _ []string) error { diff --git a/command/ibft/switch/params.go b/command/ibft/switch/params.go index 5b1ab0bd6a..c131a1fb8d 100644 --- a/command/ibft/switch/params.go +++ b/command/ibft/switch/params.go @@ -21,6 +21,7 @@ const ( minValidatorCount = "min-validator-count" maxValidatorCount = "max-validator-count" customContractAddress = "custom-contract-address" + forkEpochSize = "fork-epoch" ) var ( @@ -48,6 +49,8 @@ type switchParams struct { minValidatorCount *uint64 customContractAddressRaw string + + forkEpochSizeRaw uint64 } func (p *switchParams) getRequiredFlags() []string { @@ -214,6 +217,7 @@ func (p *switchParams) updateGenesisConfig() error { p.maxValidatorCount, p.minValidatorCount, p.customContractAddressRaw, + p.forkEpochSizeRaw, ) } @@ -240,6 +244,7 @@ func (p *switchParams) getResult() command.CommandResult { Type: p.mechanismType, From: common.JSONNumber{Value: p.from}, CustomContractAddress: p.customContractAddressRaw, + ForkEpochSize: p.forkEpochSizeRaw, } if p.deployment != nil { @@ -262,6 +267,8 @@ func (p *switchParams) getResult() command.CommandResult { result.CustomContractAddress = p.customContractAddressRaw } + result.ForkEpochSize = p.forkEpochSizeRaw + return result } @@ -273,6 +280,8 @@ func appendIBFTForks( maxValidatorCount *uint64, minValidatorCount *uint64, customContractAddress string, + forkEpochSize uint64, + ) error { ibftConfig, ok := cc.Params.Engine["ibft"].(map[string]interface{}) if !ok { @@ -299,6 +308,7 @@ func appendIBFTForks( Type: mechanismType, From: common.JSONNumber{Value: from}, CustomContractAddress: customContractAddress, + ForkEpochSize: forkEpochSize, } if mechanismType == ibft.PoS { diff --git a/command/ibft/switch/result.go b/command/ibft/switch/result.go index 628d0a8101..7ee4513b8b 100644 --- a/command/ibft/switch/result.go +++ b/command/ibft/switch/result.go @@ -17,6 +17,7 @@ type IBFTSwitchResult struct { MaxValidatorCount common.JSONNumber `json:"maxValidatorCount"` MinValidatorCount common.JSONNumber `json:"minValidatorCount"` CustomContractAddress string `json:"customContractAddress"` + ForkEpochSize uint64 `json:"forkEpochSize"` } func (r *IBFTSwitchResult) GetOutput() string { @@ -40,6 +41,7 @@ func (r *IBFTSwitchResult) GetOutput() string { outputs = append(outputs, fmt.Sprint("CustomContractAddress|", r.CustomContractAddress)) } + outputs = append(outputs, fmt.Sprint("ForkEpochSize|", r.ForkEpochSize)) buffer.WriteString(helper.FormatKV(outputs)) buffer.WriteString("\n") diff --git a/consensus/consensus.go b/consensus/consensus.go index beb7031815..7e770c96ef 100644 --- a/consensus/consensus.go +++ b/consensus/consensus.go @@ -58,6 +58,7 @@ type ConsensusInfo struct { Epoch uint64 QuorumSize int CustomContractAddress types.Address + ForkEpochSize uint64 Nonce uint64 } diff --git a/consensus/ibft/hooks.go b/consensus/ibft/hooks.go index a28d1a0a44..5306574d56 100644 --- a/consensus/ibft/hooks.go +++ b/consensus/ibft/hooks.go @@ -98,6 +98,8 @@ type ConsensusMechanism interface { // gets the custom contract address for the current mechanism getCustomContractAddress() types.Address + + getForkEpoch() uint64 } type BaseConsensusMechanism struct { @@ -116,6 +118,8 @@ type BaseConsensusMechanism struct { // Custom contract address CustomContractAddress types.Address + + ForkEpochSize uint64 } // initializeParams initializes mechanism parameters from chain config @@ -143,6 +147,8 @@ func (base *BaseConsensusMechanism) initializeParams(params *IBFTFork) error { base.CustomContractAddress = types.StringToAddress(params.CustomContractAddress) // base.ibft.customContractAddress = types.StringToAddress(params.CustomContractAddress) + base.ForkEpochSize = params.ForkEpochSize + return nil } @@ -180,6 +186,7 @@ type IBFTFork struct { MaxValidatorCount *common.JSONNumber `json:"maxValidatorCount,omitempty"` MinValidatorCount *common.JSONNumber `json:"minValidatorCount,omitempty"` CustomContractAddress string `json:"customContractAddress,omitempty"` + ForkEpochSize uint64 `json:"forkEpochSize,omitempty"` } // ConsensusMechanismFactory is the factory function to create a consensus mechanism diff --git a/consensus/ibft/ibft.go b/consensus/ibft/ibft.go index 0b4d9610ea..724b76ed0d 100644 --- a/consensus/ibft/ibft.go +++ b/consensus/ibft/ibft.go @@ -33,6 +33,11 @@ var ( ErrInvalidHookParam = errors.New("invalid IBFT hook param passed in") ) +type forkConfig struct { + customContract types.Address + forkEpoch uint64 +} + type txPoolInterface interface { Prepare() Length() uint64 @@ -169,16 +174,15 @@ func (i *backendIBFT) runHook(hookName HookType, height uint64, hookParam interf } // getCustomContractAddressFromCurrentFork returns the customContractAddress from the current fork -func (i *backendIBFT) getCustomContractAddressFromCurrentFork(height uint64) types.Address { +func (i *backendIBFT) getCurrentForkConfig(height uint64) forkConfig { for _, mechanism := range i.mechanisms { if !mechanism.isCurrent(height) { continue } - - return mechanism.getCustomContractAddress() + return forkConfig{customContract: mechanism.getCustomContractAddress(), forkEpoch: mechanism.getForkEpoch()} } - return types.ZeroAddress + return forkConfig{customContract: types.ZeroAddress, forkEpoch: 0} } func (i *backendIBFT) Initialize() error { @@ -628,7 +632,8 @@ func (i *backendIBFT) getConsensusInfoImpl() *consensus.ConsensusInfo { ValidatorAddress: i.validatorKeyAddr, Epoch: i.GetEpoch(i.blockchain.Header().Number), QuorumSize: i.quorumSize(i.blockchain.Header().Number)(i.activeValidatorSet), - CustomContractAddress: i.getCustomContractAddressFromCurrentFork(i.blockchain.Header().Number), + CustomContractAddress: i.getCurrentForkConfig(i.blockchain.Header().Number).customContract, + ForkEpochSize: i.getCurrentForkConfig(i.blockchain.Header().Number).forkEpoch, Nonce: i.txpool.GetNonce(i.validatorKeyAddr), } } diff --git a/consensus/ibft/poa.go b/consensus/ibft/poa.go index e5d62ddcf3..a21596a35f 100644 --- a/consensus/ibft/poa.go +++ b/consensus/ibft/poa.go @@ -67,6 +67,10 @@ func (poa *PoAMechanism) getCustomContractAddress() types.Address { return poa.CustomContractAddress } +func (poa *PoAMechanism) getForkEpoch() uint64 { + return poa.ForkEpochSize +} + // verifyHeadersHook verifies that the header nonce conforms to the IBFT PoA proposal format func (poa *PoAMechanism) verifyHeadersHook(nonceParam interface{}) error { // Cast the param to the nonce diff --git a/consensus/ibft/pos.go b/consensus/ibft/pos.go index 90cf221e33..c06a722d2e 100644 --- a/consensus/ibft/pos.go +++ b/consensus/ibft/pos.go @@ -63,6 +63,10 @@ func (pos *PoSMechanism) getCustomContractAddress() types.Address { return pos.CustomContractAddress } +func (pos *PoSMechanism) getForkEpoch() uint64 { + return pos.ForkEpochSize +} + // initializeParams initializes mechanism parameters from chain config func (pos *PoSMechanism) initializeParams(params *IBFTFork) error { if err := pos.BaseConsensusMechanism.initializeParams(params); err != nil { From fa9c5f9e623561bfb0745ded56ed1e8cdafb18ce Mon Sep 17 00:00:00 2001 From: Akshar Dave Date: Thu, 13 Oct 2022 15:17:17 -0400 Subject: [PATCH 2/8] use forkEpoch for calculating IsLastOfEpoch --- consensus/ibft/ibft.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/consensus/ibft/ibft.go b/consensus/ibft/ibft.go index 724b76ed0d..59cc103d63 100644 --- a/consensus/ibft/ibft.go +++ b/consensus/ibft/ibft.go @@ -173,7 +173,7 @@ func (i *backendIBFT) runHook(hookName HookType, height uint64, hookParam interf return nil } -// getCustomContractAddressFromCurrentFork returns the customContractAddress from the current fork +// getCurrentForkConfig returns the current forkConfig func (i *backendIBFT) getCurrentForkConfig(height uint64) forkConfig { for _, mechanism := range i.mechanisms { if !mechanism.isCurrent(height) { @@ -588,7 +588,8 @@ func (i *backendIBFT) GetEpoch(number uint64) uint64 { // IsLastOfEpoch checks if the block number is the last of the epoch func (i *backendIBFT) IsLastOfEpoch(number uint64) bool { - return number > 0 && number%i.epochSize == 0 + forkEpoch := i.getCurrentForkConfig(number).forkEpoch + return number > 0 && number%forkEpoch == 0 } // Close closes the IBFT consensus mechanism, and does write back to disk From fac95e7d526f4d84e95b62b980adfa57c8157125 Mon Sep 17 00:00:00 2001 From: Akshar Dave Date: Thu, 13 Oct 2022 17:17:24 -0400 Subject: [PATCH 3/8] fallback to global epoch --- consensus/ibft/ibft.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/consensus/ibft/ibft.go b/consensus/ibft/ibft.go index 59cc103d63..d9f855dbf8 100644 --- a/consensus/ibft/ibft.go +++ b/consensus/ibft/ibft.go @@ -589,6 +589,9 @@ func (i *backendIBFT) GetEpoch(number uint64) uint64 { // IsLastOfEpoch checks if the block number is the last of the epoch func (i *backendIBFT) IsLastOfEpoch(number uint64) bool { forkEpoch := i.getCurrentForkConfig(number).forkEpoch + if forkEpoch == 0 { + return number > 0 && number%i.epochSize == 0 + } return number > 0 && number%forkEpoch == 0 } From d67b01bb64566216eb575e8616928b563f7d56e3 Mon Sep 17 00:00:00 2001 From: Dan Kostiuk Date: Fri, 14 Oct 2022 10:34:00 -0400 Subject: [PATCH 4/8] now only applying customContractAddress on end of epoch --- command/ibft/switch/ibft_switch.go | 5 ++--- consensus/consensus.go | 1 - consensus/ibft/hooks.go | 2 ++ consensus/ibft/ibft.go | 11 ++++++++--- consensus/ibft/poa.go | 3 +-- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/command/ibft/switch/ibft_switch.go b/command/ibft/switch/ibft_switch.go index 9b7fda5e93..7bd48bd058 100644 --- a/command/ibft/switch/ibft_switch.go +++ b/command/ibft/switch/ibft_switch.go @@ -5,7 +5,6 @@ import ( "github.com/0xPolygon/polygon-edge/command" "github.com/0xPolygon/polygon-edge/command/helper" - "github.com/0xPolygon/polygon-edge/consensus/ibft" "github.com/spf13/cobra" ) @@ -76,8 +75,8 @@ func setFlags(cmd *cobra.Command) { cmd.Flags().Uint64Var( ¶ms.forkEpochSizeRaw, forkEpochSize, - ibft.DefaultEpochSize, - "Fork level epoch", + 0, + "fork-level epoch, overrides ibft epochSize for hook-related logic", ) } diff --git a/consensus/consensus.go b/consensus/consensus.go index 7e770c96ef..beb7031815 100644 --- a/consensus/consensus.go +++ b/consensus/consensus.go @@ -58,7 +58,6 @@ type ConsensusInfo struct { Epoch uint64 QuorumSize int CustomContractAddress types.Address - ForkEpochSize uint64 Nonce uint64 } diff --git a/consensus/ibft/hooks.go b/consensus/ibft/hooks.go index 5306574d56..e3d3c4ee02 100644 --- a/consensus/ibft/hooks.go +++ b/consensus/ibft/hooks.go @@ -99,6 +99,7 @@ type ConsensusMechanism interface { // gets the custom contract address for the current mechanism getCustomContractAddress() types.Address + // fork-specific epochSize getForkEpoch() uint64 } @@ -119,6 +120,7 @@ type BaseConsensusMechanism struct { // Custom contract address CustomContractAddress types.Address + // fork-specific epochSize ForkEpochSize uint64 } diff --git a/consensus/ibft/ibft.go b/consensus/ibft/ibft.go index d9f855dbf8..ceabca6707 100644 --- a/consensus/ibft/ibft.go +++ b/consensus/ibft/ibft.go @@ -179,10 +179,16 @@ func (i *backendIBFT) getCurrentForkConfig(height uint64) forkConfig { if !mechanism.isCurrent(height) { continue } - return forkConfig{customContract: mechanism.getCustomContractAddress(), forkEpoch: mechanism.getForkEpoch()} + return forkConfig{ + customContract: mechanism.getCustomContractAddress(), + forkEpoch: mechanism.getForkEpoch(), + } } - return forkConfig{customContract: types.ZeroAddress, forkEpoch: 0} + return forkConfig{ + customContract: types.ZeroAddress, + forkEpoch: 0, + } } func (i *backendIBFT) Initialize() error { @@ -637,7 +643,6 @@ func (i *backendIBFT) getConsensusInfoImpl() *consensus.ConsensusInfo { Epoch: i.GetEpoch(i.blockchain.Header().Number), QuorumSize: i.quorumSize(i.blockchain.Header().Number)(i.activeValidatorSet), CustomContractAddress: i.getCurrentForkConfig(i.blockchain.Header().Number).customContract, - ForkEpochSize: i.getCurrentForkConfig(i.blockchain.Header().Number).forkEpoch, Nonce: i.txpool.GetNonce(i.validatorKeyAddr), } } diff --git a/consensus/ibft/poa.go b/consensus/ibft/poa.go index a21596a35f..6879346a01 100644 --- a/consensus/ibft/poa.go +++ b/consensus/ibft/poa.go @@ -50,8 +50,7 @@ func (poa *PoAMechanism) IsAvailable(hookType HookType, height uint64) bool { case VerifyHeadersHook, ProcessHeadersHook, CandidateVoteHook: return poa.IsInRange(height) case PreStateCommitHook: - return poa.CustomContractAddress != types.ZeroAddress && - (height+1 == poa.From || poa.IsInRange(height) && poa.ibft.IsLastOfEpoch(height)) + return poa.CustomContractAddress != types.ZeroAddress && (poa.IsInRange(height) && poa.ibft.IsLastOfEpoch(height)) default: return false } From 38561bf4d42ab8b898048aae3ed090165fd763cb Mon Sep 17 00:00:00 2001 From: Dan Kostiuk Date: Fri, 14 Oct 2022 11:20:39 -0400 Subject: [PATCH 5/8] added logging --- consensus/ibft/ibft.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/consensus/ibft/ibft.go b/consensus/ibft/ibft.go index ceabca6707..9fcbca5162 100644 --- a/consensus/ibft/ibft.go +++ b/consensus/ibft/ibft.go @@ -595,7 +595,9 @@ func (i *backendIBFT) GetEpoch(number uint64) uint64 { // IsLastOfEpoch checks if the block number is the last of the epoch func (i *backendIBFT) IsLastOfEpoch(number uint64) bool { forkEpoch := i.getCurrentForkConfig(number).forkEpoch + i.logger.Debug("IsLastOfEpoch", "height", number, "forkEpoch", forkEpoch, "globalEpoch", i.epochSize) if forkEpoch == 0 { + i.logger.Debug("IsLastOfEpoch - inside if") return number > 0 && number%i.epochSize == 0 } return number > 0 && number%forkEpoch == 0 From 026f39102576d0602bfd29c921f588b993fb45cb Mon Sep 17 00:00:00 2001 From: Dan Kostiuk Date: Fri, 14 Oct 2022 11:41:48 -0400 Subject: [PATCH 6/8] allow changing forks with same type and ccAddress --- command/ibft/switch/params.go | 4 +++- consensus/ibft/ibft.go | 2 -- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/command/ibft/switch/params.go b/command/ibft/switch/params.go index c131a1fb8d..edac67b395 100644 --- a/command/ibft/switch/params.go +++ b/command/ibft/switch/params.go @@ -294,7 +294,9 @@ func appendIBFTForks( } lastFork := &ibftForks[len(ibftForks)-1] - if mechanismType == lastFork.Type && customContractAddress == lastFork.CustomContractAddress { + if mechanismType == lastFork.Type && + customContractAddress == lastFork.CustomContractAddress && + forkEpochSize == lastFork.ForkEpochSize { return errors.New(`cannot specify same IBFT type to the last fork`) } diff --git a/consensus/ibft/ibft.go b/consensus/ibft/ibft.go index 9fcbca5162..ceabca6707 100644 --- a/consensus/ibft/ibft.go +++ b/consensus/ibft/ibft.go @@ -595,9 +595,7 @@ func (i *backendIBFT) GetEpoch(number uint64) uint64 { // IsLastOfEpoch checks if the block number is the last of the epoch func (i *backendIBFT) IsLastOfEpoch(number uint64) bool { forkEpoch := i.getCurrentForkConfig(number).forkEpoch - i.logger.Debug("IsLastOfEpoch", "height", number, "forkEpoch", forkEpoch, "globalEpoch", i.epochSize) if forkEpoch == 0 { - i.logger.Debug("IsLastOfEpoch - inside if") return number > 0 && number%i.epochSize == 0 } return number > 0 && number%forkEpoch == 0 From 2d2383007e01b830f10481f6c82576a0be01e360 Mon Sep 17 00:00:00 2001 From: Dan Kostiuk Date: Fri, 14 Oct 2022 13:29:03 -0400 Subject: [PATCH 7/8] deriving preStateCommitHook validators from block header instead of snapshot --- command/ibft/switch/ibft_switch.go | 1 - consensus/ibft/hooks.go | 5 ++--- consensus/ibft/ibft.go | 9 ++++++--- consensus/ibft/poa.go | 8 ++++++-- consensus/ibft/snapshot.go | 10 ++++++++++ consensus/ibft/verifier.go | 1 - datafeed/datafeed.go | 4 ++-- datafeed/validations.go | 1 - e2e/datafeed_test.go | 1 + jsonrpc/eth_endpoint.go | 8 +------- state/runtime/precompiled/base_test.go | 2 +- syncer/client_test.go | 2 +- 12 files changed, 30 insertions(+), 22 deletions(-) diff --git a/command/ibft/switch/ibft_switch.go b/command/ibft/switch/ibft_switch.go index 7bd48bd058..12f18015b9 100644 --- a/command/ibft/switch/ibft_switch.go +++ b/command/ibft/switch/ibft_switch.go @@ -78,7 +78,6 @@ func setFlags(cmd *cobra.Command) { 0, "fork-level epoch, overrides ibft epochSize for hook-related logic", ) - } func runPreRun(_ *cobra.Command, _ []string) error { diff --git a/consensus/ibft/hooks.go b/consensus/ibft/hooks.go index e3d3c4ee02..8e6696d242 100644 --- a/consensus/ibft/hooks.go +++ b/consensus/ibft/hooks.go @@ -201,7 +201,6 @@ var mechanismBackends = map[MechanismType]ConsensusMechanismFactory{ // preStateCommitHookParams are the params passed into the preStateCommitHook type preStateCommitHookParams struct { - header *types.Header - txn *state.Transition - validatorSet ValidatorSet + header *types.Header + txn *state.Transition } diff --git a/consensus/ibft/ibft.go b/consensus/ibft/ibft.go index ceabca6707..7456aa387b 100644 --- a/consensus/ibft/ibft.go +++ b/consensus/ibft/ibft.go @@ -179,6 +179,7 @@ func (i *backendIBFT) getCurrentForkConfig(height uint64) forkConfig { if !mechanism.isCurrent(height) { continue } + return forkConfig{ customContract: mechanism.getCustomContractAddress(), forkEpoch: mechanism.getForkEpoch(), @@ -571,11 +572,12 @@ func (i *backendIBFT) GetBlockCreator(header *types.Header) (types.Address, erro // PreStateCommit a hook to be called before finalizing state transition on inserting block func (i *backendIBFT) PreStateCommit(header *types.Header, txn *state.Transition) error { params := &preStateCommitHookParams{ - header: header, - txn: txn, - validatorSet: i.activeValidatorSet, + header: header, + txn: txn, } + i.logger.Debug("extraData", header.ExtraData) + if err := i.runHook(PreStateCommitHook, header.Number, params); err != nil { return err } @@ -598,6 +600,7 @@ func (i *backendIBFT) IsLastOfEpoch(number uint64) bool { if forkEpoch == 0 { return number > 0 && number%i.epochSize == 0 } + return number > 0 && number%forkEpoch == 0 } diff --git a/consensus/ibft/poa.go b/consensus/ibft/poa.go index 6879346a01..67420a3cda 100644 --- a/consensus/ibft/poa.go +++ b/consensus/ibft/poa.go @@ -236,9 +236,13 @@ func (poa *PoAMechanism) preStateCommitHook(rawParams interface{}) error { } poa.ibft.logger.Debug("preStateCommitHook - calling setValidators here..") - snap := poa.ibft.getSnapshot(params.header.Number) - _, err := datafeed.SetValidators(params.txn, types.ZeroAddress, poa.CustomContractAddress, snap.Set) + validators, ibftExtraErr := poa.ibft.getIbftExtraValidators(params.header) + if ibftExtraErr != nil { + return ibftExtraErr + } + + _, err := datafeed.SetValidators(params.txn, types.ZeroAddress, poa.CustomContractAddress, validators) if err != nil { poa.ibft.logger.Error("failed to call setValidators", "err", err) } diff --git a/consensus/ibft/snapshot.go b/consensus/ibft/snapshot.go index 6e7d6145fa..263b2db338 100644 --- a/consensus/ibft/snapshot.go +++ b/consensus/ibft/snapshot.go @@ -233,6 +233,16 @@ func (i *backendIBFT) getSnapshot(num uint64) *Snapshot { return snap } +// getIbftExtraValidators returns the validator set from the header extraData at specified height +func (i *backendIBFT) getIbftExtraValidators(header *types.Header) ([]types.Address, error) { + extra, err := getIbftExtra(header) + if err != nil { + return nil, err + } + + return extra.Validators, nil +} + // Vote defines the vote structure type Vote struct { Validator types.Address diff --git a/consensus/ibft/verifier.go b/consensus/ibft/verifier.go index c00e69a7be..58dc6a920a 100644 --- a/consensus/ibft/verifier.go +++ b/consensus/ibft/verifier.go @@ -56,7 +56,6 @@ func (i *backendIBFT) IsValidBlock(proposal []byte) bool { } if err := i.runHook(VerifyBlockHook, newBlock.Number(), newBlock); err != nil { - //nolint:govet if errors.As(err, &errBlockVerificationFailed) { i.logger.Error("block verification fail, block at the end of epoch has transactions") } else { diff --git a/datafeed/datafeed.go b/datafeed/datafeed.go index 24ad0075b8..b042285191 100644 --- a/datafeed/datafeed.go +++ b/datafeed/datafeed.go @@ -99,10 +99,10 @@ func NewDataFeedService( } if config.VerifyOutcomeURI == "" && config.MQConfig.AMQPURI == "" { - logger.Warn("DataFeed 'verify_outcome_api_url' is missing but required for reporting - we will avoid participating in reporting gossiping") + logger.Warn("DataFeed 'verify_outcome_api_url' is missing but required for reporting - we will avoid participating in reporting gossiping") //nolint:lll + return datafeedService, nil } - // configure libp2p if network == nil { return nil, fmt.Errorf("network must be non-nil to start gossip protocol") diff --git a/datafeed/validations.go b/datafeed/validations.go index d2f804384e..7e562c2e0b 100644 --- a/datafeed/validations.go +++ b/datafeed/validations.go @@ -89,7 +89,6 @@ func (d *DataFeed) validateTimestamp(payload *proto.DataFeedReport) bool { func (d *DataFeed) validateSignatures(payload *proto.DataFeedReport) (bool, error) { sigList := strings.Split(payload.Signatures, ",") for _, sig := range sigList { - pub, err := d.signatureToAddress(payload, sig) if err != nil { diff --git a/e2e/datafeed_test.go b/e2e/datafeed_test.go index c6467f8a10..35f6d5ae40 100644 --- a/e2e/datafeed_test.go +++ b/e2e/datafeed_test.go @@ -47,6 +47,7 @@ func TestReportOutcome(t *testing.T) { t.Logf("sig1 %s", sig1) t.Logf("hashedReport1: %s", hex.EncodeToHex(hashed1)) + sig1Decoded[64] = sig1Decoded[64] - 27 pub, err := cryptoutils.SigToPub(hashed1, sig1Decoded) diff --git a/jsonrpc/eth_endpoint.go b/jsonrpc/eth_endpoint.go index 100bd652ec..e6cd73fb5b 100644 --- a/jsonrpc/eth_endpoint.go +++ b/jsonrpc/eth_endpoint.go @@ -87,7 +87,7 @@ var ( ) // ChainId returns the chain id of the client -//nolint:stylecheck, gofmt +//nolint:stylecheck func (e *Eth) ChainId() (interface{}, error) { return argUintPtr(e.chainID), nil } @@ -407,7 +407,6 @@ func (e *Eth) GetStorageAt( // Get the storage for the passed in location result, err := e.store.GetStorage(header.StateRoot, address, index) if err != nil { - //nolint:govet if errors.As(err, &ErrStateNotFound) { return argBytesPtr(types.ZeroHash[:]), nil } @@ -540,7 +539,6 @@ func (e *Eth) EstimateGas(arg *txnArgs, rawNum *BlockNumber) (interface{}, error accountBalance := big.NewInt(0) acc, err := e.store.GetAccount(header.StateRoot, transaction.From) - //nolint:govet if err != nil && !errors.As(err, &ErrStateNotFound) { // An unrelated error occurred, return it return nil, err @@ -584,7 +582,6 @@ func (e *Eth) EstimateGas(arg *txnArgs, rawNum *BlockNumber) (interface{}, error // Checks if executor level valid gas errors occurred isGasApplyError := func(err error) bool { // Not linting this as the underlying error is actually wrapped - //nolint:govet return errors.As(err, &state.ErrNotEnoughIntrinsicGas) } @@ -711,7 +708,6 @@ func (e *Eth) GetBalance(address types.Address, filter BlockNumberOrHash) (inter // Extract the account balance acc, err := e.store.GetAccount(header.StateRoot, address) - //nolint:govet if errors.As(err, &ErrStateNotFound) { // Account not found, return an empty account return argUintPtr(0), nil @@ -778,7 +774,6 @@ func (e *Eth) GetCode(address types.Address, filter BlockNumberOrHash) (interfac emptySlice := []byte{} acc, err := e.store.GetAccount(header.StateRoot, address) - //nolint:govet if errors.As(err, &ErrStateNotFound) { // If the account doesn't exist / is not initialized yet, // return the default value @@ -869,7 +864,6 @@ func (e *Eth) getNextNonce(address types.Address, number BlockNumber) (uint64, e acc, err := e.store.GetAccount(header.StateRoot, address) - //nolint:govet if errors.As(err, &ErrStateNotFound) { // If the account doesn't exist / isn't initialized, // return a nonce value of 0 diff --git a/state/runtime/precompiled/base_test.go b/state/runtime/precompiled/base_test.go index 1901c53569..616ccd7a15 100644 --- a/state/runtime/precompiled/base_test.go +++ b/state/runtime/precompiled/base_test.go @@ -1,4 +1,4 @@ -//nolint: lll,gofmt +//nolint: lll package precompiled import ( diff --git a/syncer/client_test.go b/syncer/client_test.go index 268918d9c6..e2498263a6 100644 --- a/syncer/client_test.go +++ b/syncer/client_test.go @@ -371,7 +371,7 @@ func TestPeerConnectionUpdateEventCh(t *testing.T) { // Make sure the peer shouldn't emit status if the shouldEmitBlocks flag is set. // The subtests cannot contain t.Parallel() due to how // the test is organized -//nolint:tparallel, gofmt +//nolint:tparallel func Test_shouldEmitBlocks(t *testing.T) { t.Parallel() From 428b54f221e6aab4c438786a56ddc5da8411dfb5 Mon Sep 17 00:00:00 2001 From: Dan Kostiuk Date: Fri, 14 Oct 2022 14:43:28 -0400 Subject: [PATCH 8/8] code cleanup --- consensus/ibft/extra.go | 10 ++++++++++ consensus/ibft/ibft.go | 2 -- consensus/ibft/poa.go | 4 ++-- consensus/ibft/snapshot.go | 10 ---------- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/consensus/ibft/extra.go b/consensus/ibft/extra.go index 0cdee219a0..6940e54e41 100644 --- a/consensus/ibft/extra.go +++ b/consensus/ibft/extra.go @@ -74,6 +74,16 @@ func getIbftExtra(h *types.Header) (*IstanbulExtra, error) { return extra, nil } +// getIbftExtraValidators returns the validator set from the header extraData at specified height +func (i *backendIBFT) getIbftExtraValidators(header *types.Header) ([]types.Address, error) { + extra, err := getIbftExtra(header) + if err != nil { + return nil, err + } + + return extra.Validators, nil +} + // IstanbulExtra defines the structure of the extra field for Istanbul type IstanbulExtra struct { Validators []types.Address diff --git a/consensus/ibft/ibft.go b/consensus/ibft/ibft.go index 7456aa387b..c9a21ba717 100644 --- a/consensus/ibft/ibft.go +++ b/consensus/ibft/ibft.go @@ -576,8 +576,6 @@ func (i *backendIBFT) PreStateCommit(header *types.Header, txn *state.Transition txn: txn, } - i.logger.Debug("extraData", header.ExtraData) - if err := i.runHook(PreStateCommitHook, header.Number, params); err != nil { return err } diff --git a/consensus/ibft/poa.go b/consensus/ibft/poa.go index 67420a3cda..26d51b3759 100644 --- a/consensus/ibft/poa.go +++ b/consensus/ibft/poa.go @@ -235,13 +235,13 @@ func (poa *PoAMechanism) preStateCommitHook(rawParams interface{}) error { return ErrInvalidHookParam } - poa.ibft.logger.Debug("preStateCommitHook - calling setValidators here..") - validators, ibftExtraErr := poa.ibft.getIbftExtraValidators(params.header) if ibftExtraErr != nil { return ibftExtraErr } + poa.ibft.logger.Debug("preStateCommitHook - calling setValidators here..", "validators", validators) + _, err := datafeed.SetValidators(params.txn, types.ZeroAddress, poa.CustomContractAddress, validators) if err != nil { poa.ibft.logger.Error("failed to call setValidators", "err", err) diff --git a/consensus/ibft/snapshot.go b/consensus/ibft/snapshot.go index 263b2db338..6e7d6145fa 100644 --- a/consensus/ibft/snapshot.go +++ b/consensus/ibft/snapshot.go @@ -233,16 +233,6 @@ func (i *backendIBFT) getSnapshot(num uint64) *Snapshot { return snap } -// getIbftExtraValidators returns the validator set from the header extraData at specified height -func (i *backendIBFT) getIbftExtraValidators(header *types.Header) ([]types.Address, error) { - extra, err := getIbftExtra(header) - if err != nil { - return nil, err - } - - return extra.Validators, nil -} - // Vote defines the vote structure type Vote struct { Validator types.Address