Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP - Fork level Epoch #102

Draft
wants to merge 8 commits into
base: sxbet-validators/data-oracle-toronto
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
now only applying customContractAddress on end of epoch
  • Loading branch information
dankostiuk committed Oct 14, 2022
commit d67b01bb64566216eb575e8616928b563f7d56e3
5 changes: 2 additions & 3 deletions command/ibft/switch/ibft_switch.go
Original file line number Diff line number Diff line change
@@ -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(
&params.forkEpochSizeRaw,
forkEpochSize,
ibft.DefaultEpochSize,
"Fork level epoch",
0,
"fork-level epoch, overrides ibft epochSize for hook-related logic",
)

}
1 change: 0 additions & 1 deletion consensus/consensus.go
Original file line number Diff line number Diff line change
@@ -58,7 +58,6 @@ type ConsensusInfo struct {
Epoch uint64
QuorumSize int
CustomContractAddress types.Address
ForkEpochSize uint64
Nonce uint64
}

2 changes: 2 additions & 0 deletions consensus/ibft/hooks.go
Original file line number Diff line number Diff line change
@@ -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
}

11 changes: 8 additions & 3 deletions consensus/ibft/ibft.go
Original file line number Diff line number Diff line change
@@ -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),
}
}
3 changes: 1 addition & 2 deletions consensus/ibft/poa.go
Original file line number Diff line number Diff line change
@@ -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
}