-
Notifications
You must be signed in to change notification settings - Fork 620
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: make chunk and batch proposers respect fork boundaries (#1174)
Co-authored-by: georgehao <[email protected]>
- Loading branch information
1 parent
63f1b1e
commit 96179d1
Showing
15 changed files
with
286 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package forks | ||
|
||
import ( | ||
"math/big" | ||
"sort" | ||
|
||
"github.com/scroll-tech/go-ethereum/params" | ||
) | ||
|
||
// CollectSortedForkHeights returns a sorted set of block numbers that one or more forks are activated on | ||
func CollectSortedForkHeights(config *params.ChainConfig) ([]uint64, map[uint64]bool) { | ||
forkHeightsMap := make(map[uint64]bool) | ||
for _, fork := range []*big.Int{ | ||
config.HomesteadBlock, | ||
config.DAOForkBlock, | ||
config.EIP150Block, | ||
config.EIP155Block, | ||
config.EIP158Block, | ||
config.ByzantiumBlock, | ||
config.ConstantinopleBlock, | ||
config.PetersburgBlock, | ||
config.IstanbulBlock, | ||
config.MuirGlacierBlock, | ||
config.BerlinBlock, | ||
config.LondonBlock, | ||
config.ArrowGlacierBlock, | ||
config.ArchimedesBlock, | ||
config.ShanghaiBlock, | ||
} { | ||
if fork == nil { | ||
continue | ||
} else if height := fork.Uint64(); height != 0 { | ||
forkHeightsMap[height] = true | ||
} | ||
} | ||
|
||
var forkHeights []uint64 | ||
for height := range forkHeightsMap { | ||
forkHeights = append(forkHeights, height) | ||
} | ||
sort.Slice(forkHeights, func(i, j int) bool { | ||
return forkHeights[i] < forkHeights[j] | ||
}) | ||
return forkHeights, forkHeightsMap | ||
} | ||
|
||
// BlocksUntilFork returns the number of blocks until the next fork | ||
// returns 0 if there is no fork scheduled for the future | ||
func BlocksUntilFork(blockHeight uint64, forkHeights []uint64) uint64 { | ||
for _, forkHeight := range forkHeights { | ||
if forkHeight > blockHeight { | ||
return forkHeight - blockHeight | ||
} | ||
} | ||
return 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package forks | ||
|
||
import ( | ||
"math/big" | ||
"testing" | ||
|
||
"github.com/scroll-tech/go-ethereum/params" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestCollectSortedForkBlocks(t *testing.T) { | ||
l, m := CollectSortedForkHeights(¶ms.ChainConfig{ | ||
EIP155Block: big.NewInt(4), | ||
EIP158Block: big.NewInt(3), | ||
ByzantiumBlock: big.NewInt(3), | ||
ConstantinopleBlock: big.NewInt(0), | ||
}) | ||
require.Equal(t, l, []uint64{ | ||
3, | ||
4, | ||
}) | ||
require.Equal(t, map[uint64]bool{ | ||
3: true, | ||
4: true, | ||
}, m) | ||
} | ||
|
||
func TestBlocksUntilFork(t *testing.T) { | ||
tests := map[string]struct { | ||
block uint64 | ||
forks []uint64 | ||
expected uint64 | ||
}{ | ||
"NoFork": { | ||
block: 44, | ||
forks: []uint64{}, | ||
expected: 0, | ||
}, | ||
"BeforeFork": { | ||
block: 0, | ||
forks: []uint64{1, 5}, | ||
expected: 1, | ||
}, | ||
"OnFork": { | ||
block: 1, | ||
forks: []uint64{1, 5}, | ||
expected: 4, | ||
}, | ||
"OnLastFork": { | ||
block: 5, | ||
forks: []uint64{1, 5}, | ||
expected: 0, | ||
}, | ||
"AfterFork": { | ||
block: 5, | ||
forks: []uint64{1, 5}, | ||
expected: 0, | ||
}, | ||
} | ||
|
||
for name, test := range tests { | ||
t.Run(name, func(t *testing.T) { | ||
require.Equal(t, test.expected, BlocksUntilFork(test.block, test.forks)) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"config": { | ||
"chainId": 33, | ||
"homesteadBlock": 0, | ||
"eip155Block": 0, | ||
"eip158Block": 0 | ||
}, | ||
"nonce": "0x0000000000000033", | ||
"timestamp": "0x0", | ||
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", | ||
"gasLimit": "0x8000000", | ||
"difficulty": "0x100", | ||
"mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000", | ||
"coinbase": "0x3333333333333333333333333333333333333333", | ||
"alloc": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.