Skip to content

Commit 350e0ba

Browse files
authored
Support Fermi HF for testnet (#77)
1 parent 289b5e6 commit 350e0ba

File tree

13 files changed

+303
-122
lines changed

13 files changed

+303
-122
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ jobs:
5454
run: |
5555
make chain
5656
make contracts
57-
# Wait for Maxwell HF to be enabled (0.75sec * 2000)
58-
sleep 1500
57+
# Wait for Latest HF to be enabled (0.45sec * 2000)
58+
sleep 900
5959
make relayer
6060
make test
6161
- name: integration-test

e2e/chains/bsc/Dockerfile.bootstrap

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ RUN curl -fsSL https://deb.nodesource.com/setup_lts.x nodesource_setup.sh | bash
1919
&& apt-get install --no-install-recommends -y nodejs \
2020
&& rm -rf /var/cache/apt/*
2121

22+
# https://github.com/bnb-chain/bsc/blob/v1.6.2/core/systemcontracts/upgrade.go#L1031C20-L1031C117
2223
RUN git clone https://github.com/bnb-chain/bsc-genesis-contract -b develop /root/genesis \
23-
&& cd /root/genesis && git checkout bf3ac733f8aaf93ed88ca0ad2dcddd051166e4e1 && npm ci
24+
&& cd /root/genesis && git checkout 34618f607f8356cf147dde6a69fae150bd53d5bf && npm ci
2425

2526
RUN cd /root/genesis && /root/.local/bin/poetry install
2627
RUN cd /root/genesis && forge install --no-git foundry-rs/forge-std@v1.7.3

e2e/chains/bsc/docker-compose.bsc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ services:
55
dockerfile: Dockerfile.bsc
66
args:
77
GIT_SOURCE: https://github.com/bnb-chain/bsc
8-
GIT_CHECKOUT_BRANCH: v1.6.1-beta-feature-ScalableDB
8+
GIT_CHECKOUT_BRANCH: v1.6.4
99
image: bsc-geth:docker-local

e2e/chains/bsc/genesis/genesis-template.template

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"pragueTime": 0,
3838
"lorentzTime": 0,
3939
"maxwellTime": 0,
40+
"fermiTime": 0,
4041
"blobSchedule": {
4142
"cancun": {
4243
"target": 3,

module/facade.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ import (
77
)
88

99
// Facade for tool modules
10-
func QueryFinalizedHeader(ctx context.Context, fn getHeaderFn, height uint64, limitHeight uint64) ([]*ETHHeader, error) {
11-
return queryFinalizedHeader(ctx, fn, height, limitHeight)
12-
}
13-
1410
func QueryValidatorSetAndTurnLength(ctx context.Context, fn getHeaderFn, height uint64) (Validators, uint8, error) {
1511
return queryValidatorSetAndTurnLength(ctx, fn, height)
1612
}

module/fork_spec.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const (
2222
Mainnet Network = "mainnet"
2323
)
2424

25-
var localLatestHF isForkSpec_HeightOrTimestamp = &ForkSpec_Height{Height: 2}
25+
var localLatestHF isForkSpec_HeightOrTimestamp = &ForkSpec_Height{Height: 3}
2626

2727
func init() {
2828
localLatestHFTimestamp := os.Getenv("LOCAL_LATEST_HF_TIMESTAMP")
@@ -39,6 +39,7 @@ const (
3939
indexPascalHF = 0
4040
indexLorentzHF = 1
4141
indexMaxwellHF = 2
42+
indexFermiHF = 3
4243
)
4344

4445
func getForkSpecParams() []*ForkSpec {
@@ -50,6 +51,7 @@ func getForkSpecParams() []*ForkSpec {
5051
MaxTurnLength: 9,
5152
GasLimitBoundDivider: 256,
5253
EnableHeaderMsec: false,
54+
KAncestorGenerationDepth: 1,
5355
},
5456
// Lorentz HF
5557
{
@@ -58,6 +60,7 @@ func getForkSpecParams() []*ForkSpec {
5860
MaxTurnLength: 64,
5961
GasLimitBoundDivider: 1024,
6062
EnableHeaderMsec: true,
63+
KAncestorGenerationDepth: 1,
6164
},
6265
// Maxwell HF
6366
{
@@ -66,6 +69,16 @@ func getForkSpecParams() []*ForkSpec {
6669
MaxTurnLength: 64,
6770
GasLimitBoundDivider: 1024,
6871
EnableHeaderMsec: true,
72+
KAncestorGenerationDepth: 1,
73+
},
74+
// Fermi HF
75+
{
76+
AdditionalHeaderItemCount: 1,
77+
EpochLength: 1000,
78+
MaxTurnLength: 64,
79+
GasLimitBoundDivider: 1024,
80+
EnableHeaderMsec: true,
81+
KAncestorGenerationDepth: 3,
6982
},
7083
}
7184
}
@@ -76,12 +89,14 @@ func GetForkParameters(network Network) []*ForkSpec {
7689
case Localnet:
7790
hardForks[indexPascalHF].HeightOrTimestamp = &ForkSpec_Height{Height: 0}
7891
hardForks[indexLorentzHF].HeightOrTimestamp = &ForkSpec_Height{Height: 1}
79-
hardForks[indexMaxwellHF].HeightOrTimestamp = localLatestHF
92+
hardForks[indexMaxwellHF].HeightOrTimestamp = &ForkSpec_Height{Height: 2}
93+
hardForks[indexFermiHF].HeightOrTimestamp = localLatestHF
8094
return hardForks
8195
case Testnet:
8296
hardForks[indexPascalHF].HeightOrTimestamp = &ForkSpec_Height{Height: 48576786}
8397
hardForks[indexLorentzHF].HeightOrTimestamp = &ForkSpec_Height{Height: 49791365}
8498
hardForks[indexMaxwellHF].HeightOrTimestamp = &ForkSpec_Height{Height: 52552978}
99+
hardForks[indexFermiHF].HeightOrTimestamp = &ForkSpec_Height{Height: 71859053}
85100
return hardForks
86101
case Mainnet:
87102
hardForks[indexPascalHF].HeightOrTimestamp = &ForkSpec_Height{Height: 47618307}
@@ -91,6 +106,8 @@ func GetForkParameters(network Network) []*ForkSpec {
91106
// https://bscscan.com/block/52337091
92107
// https://github.com/bnb-chain/bsc/releases/tag/v1.5.16
93108
hardForks[indexMaxwellHF].HeightOrTimestamp = &ForkSpec_Height{Height: 52337091}
109+
// https://github.com/bnb-chain/bsc/pull/3466/files
110+
hardForks[indexFermiHF].HeightOrTimestamp = &ForkSpec_Timestamp{Timestamp: 1768357800 * 1000}
94111
return hardForks
95112
}
96113
return nil

module/header_query.go

Lines changed: 60 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111

1212
type getHeaderFn func(context.Context, uint64) (*types.Header, error)
1313

14-
func queryLatestFinalizedHeader(ctx context.Context, getHeader getHeaderFn, latestBlockNumber uint64) (uint64, []*ETHHeader, error) {
14+
func queryLatestFinalizedHeader(ctx context.Context, getHeader getHeaderFn, latestBlockNumber uint64, forkSpecs []*ForkSpec) (uint64, []*ETHHeader, error) {
1515
logger := log.GetLogger()
1616
for i := latestBlockNumber; i > 0; i-- {
1717
header, err := getHeader(ctx, i)
@@ -29,7 +29,7 @@ func queryLatestFinalizedHeader(ctx context.Context, getHeader getHeaderFn, late
2929

3030
logger.DebugContext(ctx, "Try to seek verifying headers to finalize", "probablyFinalized", probablyFinalized, "latest", latestBlockNumber)
3131

32-
headers, err := queryFinalizedHeader(ctx, getHeader, probablyFinalized, latestBlockNumber)
32+
headers, err := queryFinalizedHeader(ctx, getHeader, probablyFinalized, latestBlockNumber, forkSpecs)
3333
if err != nil {
3434
return 0, nil, err
3535
}
@@ -41,31 +41,71 @@ func queryLatestFinalizedHeader(ctx context.Context, getHeader getHeaderFn, late
4141
return 0, nil, fmt.Errorf("no finalized header found: %d", latestBlockNumber)
4242
}
4343

44-
func queryFinalizedHeader(ctx context.Context, fn getHeaderFn, height uint64, limitHeight uint64) ([]*ETHHeader, error) {
44+
// queryFinalizedHeader returns finalized header sequence
45+
// ex)
46+
// 72486611 -> target 72486610 -> target 72486608
47+
// 72486611 --------------------> source 72486608
48+
//
49+
// 72486610 -> target 72486608 -> target 72486607
50+
// 72486610 --------------------> source 72486607
51+
//
52+
// 72476712 -> target 72476710 -> target 72476708
53+
// 72476712 --------------------> source 72476708
54+
func queryFinalizedHeader(ctx context.Context, fn getHeaderFn, height uint64, limitHeight uint64, forkSpecs []*ForkSpec) ([]*ETHHeader, error) {
4555
var ethHeaders []*ETHHeader
4656
for i := height; i+2 <= limitHeight; i++ {
47-
targetBlock, targetETHHeader, _, err := queryETHHeader(ctx, fn, i)
48-
if err != nil {
49-
return nil, err
50-
}
51-
childBlock, childETHHeader, childVote, err := queryETHHeader(ctx, fn, i+1)
52-
if err != nil {
53-
return nil, err
54-
}
55-
_, grandChildETHHeader, grandChildVote, err := queryETHHeader(ctx, fn, i+2)
57+
finalizedBlock, finalizedETHHeader, _, err := queryETHHeader(ctx, fn, i)
5658
if err != nil {
5759
return nil, err
5860
}
61+
ethHeaders = append(ethHeaders, finalizedETHHeader)
5962

60-
if childVote == nil || grandChildVote == nil ||
61-
grandChildVote.Data.SourceNumber != targetBlock.Number.Uint64() ||
62-
grandChildVote.Data.SourceNumber != childVote.Data.TargetNumber ||
63-
grandChildVote.Data.TargetNumber != childBlock.Number.Uint64() {
64-
// Append to verify header sequence
65-
ethHeaders = append(ethHeaders, targetETHHeader)
66-
continue
63+
// child: descendant whose vote.TargetNumber == finalized.Number
64+
var childList []*ETHHeader
65+
for j := i + 1; j+1 <= limitHeight; j++ {
66+
childHeader, childETHHeader, childVote, err := queryETHHeader(ctx, fn, j)
67+
if err != nil {
68+
return nil, err
69+
}
70+
childList = append(childList, childETHHeader)
71+
if childVote == nil {
72+
continue
73+
}
74+
if childVote.Data.TargetNumber != finalizedBlock.Number.Uint64() || childVote.Data.TargetHash != finalizedBlock.Hash() {
75+
continue
76+
}
77+
78+
// grandChild: descendant whose vote.TargetNumber == child.Number and vote.SourceNumber == child.TargetNumber
79+
var grandChildList []*ETHHeader
80+
for k := j + 1; k <= limitHeight; k++ {
81+
grandChildHeader, grandChildETHHeader, grandChildVote, err := queryETHHeader(ctx, fn, k)
82+
if err != nil {
83+
return nil, err
84+
}
85+
86+
// Ensure distance is less than or equal to k_ancestor_generation_depth
87+
currentForkSpec, _, err := FindTargetForkSpec(forkSpecs, grandChildHeader.Number.Uint64(), MilliTimestamp(grandChildHeader))
88+
if err != nil {
89+
return nil, err
90+
}
91+
if k-j > uint64(currentForkSpec.KAncestorGenerationDepth) {
92+
break
93+
}
94+
95+
grandChildList = append(grandChildList, grandChildETHHeader)
96+
if grandChildVote == nil {
97+
continue
98+
}
99+
if grandChildVote.Data.SourceNumber == childVote.Data.TargetNumber &&
100+
grandChildVote.Data.SourceHash == childVote.Data.TargetHash &&
101+
grandChildVote.Data.TargetNumber == childHeader.Number.Uint64() &&
102+
grandChildVote.Data.TargetHash == childHeader.Hash() {
103+
// Found headers.
104+
// ELC Requires all sequential headers from the starting header
105+
return append(append(ethHeaders, childList...), grandChildList...), nil
106+
}
107+
}
67108
}
68-
return append(ethHeaders, targetETHHeader, childETHHeader, grandChildETHHeader), nil
69109
}
70110
log.GetLogger().DebugContext(ctx, "Insufficient verifying headers to finalize", "height", height, "limit", limitHeight)
71111
return nil, nil

0 commit comments

Comments
 (0)