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

[DON't MERGE] Revert "cmd/devp2p, eth: drop eth/66 (#28239)" #1071

Open
wants to merge 3 commits into
base: syncUpstream/active
Choose a base branch
from
Open
Show file tree
Hide file tree
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
26 changes: 5 additions & 21 deletions core/forkid/forkid.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func NewID(config *params.ChainConfig, genesis *types.Block, head, time uint64)
hash := crc32.ChecksumIEEE(genesis.Hash().Bytes())

// Calculate the current fork checksum and the next fork block
forksByBlock, forksByTime := gatherForks(config, genesis.Time())
forksByBlock, _ := gatherForks(config, genesis.Time())
for _, fork := range forksByBlock {
if fork <= head {
// Fork already passed, checksum the previous hash and the fork number
Expand All @@ -86,14 +86,6 @@ func NewID(config *params.ChainConfig, genesis *types.Block, head, time uint64)
}
return ID{Hash: checksumToBytes(hash), Next: fork}
}
for _, fork := range forksByTime {
if fork <= time {
// Fork already passed, checksum the previous hash and fork timestamp
hash = checksumUpdate(hash, fork)
continue
}
return ID{Hash: checksumToBytes(hash), Next: fork}
}
return ID{Hash: checksumToBytes(hash), Next: 0}
}

Expand Down Expand Up @@ -134,9 +126,8 @@ func NewStaticFilter(config *params.ChainConfig, genesis *types.Block) Filter {
func newFilter(config *params.ChainConfig, genesis *types.Block, headfn func() (uint64, uint64)) Filter {
// Calculate the all the valid fork hash and fork next combos
var (
forksByBlock, forksByTime = gatherForks(config, genesis.Time())
forks = append(append([]uint64{}, forksByBlock...), forksByTime...)
sums = make([][4]byte, len(forks)+1) // 0th is the genesis
forks, _ = gatherForks(config, genesis.Time())
sums = make([][4]byte, len(forks)+1) // 0th is the genesis
)
hash := crc32.ChecksumIEEE(genesis.Hash().Bytes())
sums[0] = checksumToBytes(hash)
Expand All @@ -147,10 +138,6 @@ func newFilter(config *params.ChainConfig, genesis *types.Block, headfn func() (
// Add two sentries to simplify the fork checks and don't require special
// casing the last one.
forks = append(forks, math.MaxUint64) // Last fork will never be passed
if len(forksByTime) == 0 {
// In purely block based forks, avoid the sentry spilling into timestapt territory
forksByBlock = append(forksByBlock, math.MaxUint64) // Last fork will never be passed
}
// Create a validator that will filter out incompatible chains
Comment on lines -150 to 141
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if we comment out instead of deleting?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or maybe no need. we can just revert back in the future

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but I think it will be good if we can practice re-init genesis on sepolia

return func(id ID) error {
// Run the fork checksum validation ruleset:
Expand All @@ -172,13 +159,10 @@ func newFilter(config *params.ChainConfig, genesis *types.Block, headfn func() (
// the remote, but at this current point in time we don't have enough
// information.
// 4. Reject in all other cases.
block, time := headfn()
block, _ := headfn()
for i, fork := range forks {
// Pick the head comparison based on fork progression
head := block
if i >= len(forksByBlock) {
head = time
}
// If our head is beyond this fork, continue to the next (we have a dummy
// fork of maxuint64 as the last item to always fail this check eventually).
if head >= fork {
Expand All @@ -189,7 +173,7 @@ func newFilter(config *params.ChainConfig, genesis *types.Block, headfn func() (
if sums[i] == id.Hash {
// Fork checksum matched, check if a remote future fork block already passed
// locally without the local node being aware of it (rule #1a).
if id.Next > 0 && (head >= id.Next || (id.Next > timestampThreshold && time >= id.Next)) {
if id.Next > 0 && head >= id.Next {
return ErrLocalIncompatibleOrStale
}
// Haven't passed locally a remote-only fork, accept the connection (rule #1b).
Expand Down
25 changes: 25 additions & 0 deletions core/forkid/forkid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,3 +448,28 @@ func TestTimeBasedForkInGenesis(t *testing.T) {
}
}
}

func TestScroll(t *testing.T) {
tests := []struct {
config *params.ChainConfig
genesis *types.Block
head uint64
time uint64
want ID
}{
// Scroll test cases
{
params.ScrollMainnetChainConfig,
core.DefaultScrollMainnetGenesisBlock().ToBlock(),
10281275,
1729250728, // omit timestamp-based forks
ID{Hash: checksumToBytes(0x18d3c8d9), Next: 0}, // 0x18d3c8d9 is fetched from develop branch
},
}

for i, tt := range tests {
if have := NewID(tt.config, tt.genesis, tt.head, tt.time); have != tt.want {
t.Errorf("test %d: fork ID mismatch: have %x, want %x", i, have, tt.want)
}
}
}
Loading