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

Move validator set snapshot computation to bor_heimdall stage #8646

Merged
merged 58 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
8eb752e
Move validator set snapshot computation to bor_heimdall stage
AlexeyAkhunov Sep 14, 2023
b5bfa01
Merge remote-tracking branch 'origin/devel' into valid-snap
AlexeyAkhunov Sep 15, 2023
d58d49d
Bor
AlexeyAkhunov Sep 21, 2023
51cd65f
Merge remote-tracking branch 'origin/devel' into valid-snap
AlexeyAkhunov Sep 22, 2023
cb3c197
Intermediate
AlexeyAkhunov Oct 2, 2023
7587e79
Merge remote-tracking branch 'origin/devel' into valid-snap
AlexeyAkhunov Oct 2, 2023
0edce98
Merge remote-tracking branch 'origin/devel' into valid-snap
AlexeyAkhunov Oct 3, 2023
7ec0a99
Remove logging
AlexeyAkhunov Oct 3, 2023
6e02930
Merge remote-tracking branch 'origin/devel' into valid-snap
AlexeyAkhunov Oct 6, 2023
d7c0973
Merge remote-tracking branch 'origin/devel' into valid-snap
AlexeyAkhunov Oct 6, 2023
f2f992c
Verifications
AlexeyAkhunov Oct 6, 2023
4d391c3
Get 0 span
AlexeyAkhunov Oct 6, 2023
9f99972
Merge remote-tracking branch 'origin/devel' into valid-snap
AlexeyAkhunov Oct 6, 2023
504534b
Merge remote-tracking branch 'origin/devel' into valid-snap
AlexeyAkhunov Oct 7, 2023
e5443ca
commit span
AlexeyAkhunov Oct 7, 2023
707453b
Merge remote-tracking branch 'origin/devel' into valid-snap
AlexeyAkhunov Oct 7, 2023
060646c
Fix unwind
AlexeyAkhunov Oct 8, 2023
92ac166
Merge remote-tracking branch 'origin/devel' into valid-snap
AlexeyAkhunov Oct 8, 2023
024dd57
Remove changes
AlexeyAkhunov Oct 8, 2023
cedbf7f
Cleanup
AlexeyAkhunov Oct 8, 2023
dc70f94
Cleanup
AlexeyAkhunov Oct 8, 2023
ee4e5f2
Fetch one span in advance
AlexeyAkhunov Oct 9, 2023
13a6e09
Merge remote-tracking branch 'origin/devel' into valid-snap
AlexeyAkhunov Oct 9, 2023
771b526
Move extraData check to bor_heimdall stage
AlexeyAkhunov Oct 10, 2023
b70d79b
Merge remote-tracking branch 'origin/devel' into valid-snap
AlexeyAkhunov Oct 10, 2023
9c6e4db
Fixup
AlexeyAkhunov Oct 10, 2023
fb5a555
Intermediate
AlexeyAkhunov Oct 10, 2023
5a18fa5
Fixes
AlexeyAkhunov Oct 12, 2023
6d71289
Merge remote-tracking branch 'origin/devel' into valid-snap
AlexeyAkhunov Oct 12, 2023
a2c218e
Intermediate
AlexeyAkhunov Oct 12, 2023
e92aced
Intermediate|
AlexeyAkhunov Oct 15, 2023
be9e1f1
fixes
AlexeyAkhunov Oct 15, 2023
1be621c
Merge remote-tracking branch 'origin' into valid-snap
AlexeyAkhunov Oct 15, 2023
60fd453
Restore validator set
AlexeyAkhunov Oct 15, 2023
5070625
Fix lint
Oct 15, 2023
23c25eb
Debug print
AlexeyAkhunov Oct 16, 2023
2e0cc7c
Fix tests
AlexeyAkhunov Oct 17, 2023
720c060
Merge remote-tracking branch 'origin/devel' into valid-snap
AlexeyAkhunov Oct 17, 2023
a53691c
combine recents and signatures
Oct 17, 2023
f5851de
Fix compilation
Oct 17, 2023
5d9f2c3
Merge remote-tracking branch 'origin/devel' into valid-snap
AlexeyAkhunov Oct 18, 2023
b2faa44
Add optimisation
AlexeyAkhunov Oct 18, 2023
1c8f484
Fix BorSpan lookup
AlexeyAkhunov Oct 18, 2023
92aed2e
Merge remote-tracking branch 'origin/devel' into valid-snap
AlexeyAkhunov Oct 18, 2023
6ba3443
Merge remote-tracking branch 'origin/devel' into valid-snap
AlexeyAkhunov Oct 19, 2023
7a864b6
Fix logging
AlexeyAkhunov Oct 19, 2023
42b9328
Merge remote-tracking branch 'origin/devel' into valid-snap
AlexeyAkhunov Oct 19, 2023
6788b4a
Fix merge cleanup for borspan files
AlexeyAkhunov Oct 19, 2023
7bdf937
Merge remote-tracking branch 'origin/devel' into valid-snap
AlexeyAkhunov Oct 20, 2023
0cd719e
Merge remote-tracking branch 'origin/devel' into valid-snap-1
AlexeyAkhunov Nov 4, 2023
4c64a25
Merge remote-tracking branch 'origin/devel' into valid-snap-1
AlexeyAkhunov Nov 4, 2023
f3d4d3e
Merge remote-tracking branch 'origin/devel' into valid-snap-1
AlexeyAkhunov Nov 4, 2023
d379133
cleanup
AlexeyAkhunov Nov 4, 2023
caaca20
cleanup
AlexeyAkhunov Nov 4, 2023
038251b
Merge remote-tracking branch 'origin/devel' into valid-snap-1
AlexeyAkhunov Nov 4, 2023
921273a
Merge remote-tracking branch 'origin/devel' into valid-snap-1
AlexeyAkhunov Nov 4, 2023
8e8c45c
Merge remote-tracking branch 'origin/devel' into valid-snap-1
AlexeyAkhunov Nov 4, 2023
159dee7
Fix mumbai sync from scratch
AlexeyAkhunov Nov 5, 2023
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
Fix unwind
  • Loading branch information
AlexeyAkhunov committed Oct 8, 2023
commit 060646ce3b54832d1ed3cb96b9aeef8a1b955684
6 changes: 3 additions & 3 deletions consensus/bor/bor.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ func New(
libcommon.Address{},
func(_ libcommon.Address, _ string, i []byte) ([]byte, error) {
// return an error to prevent panics
return nil, &UnauthorizedSignerError{libcommon.Hash{}, 0, libcommon.Address{}.Bytes()}
return nil, &UnauthorizedSignerError{0, libcommon.Address{}.Bytes()}
},
})

Expand Down Expand Up @@ -871,7 +871,7 @@ func (c *Bor) verifySeal(chain consensus.ChainHeaderReader, header *types.Header

if !snap.ValidatorSet.HasAddress(signer) {
// Check the UnauthorizedSignerError.Error() msg to see why we pass number-1
return &UnauthorizedSignerError{header.Hash(), number, signer.Bytes()}
return &UnauthorizedSignerError{number, signer.Bytes()}
}

succession, err := snap.GetSignerSuccessionNumber(signer)
Expand Down Expand Up @@ -1134,7 +1134,7 @@ func (c *Bor) Seal(chain consensus.ChainHeaderReader, block *types.Block, result
// Bail out if we're unauthorized to sign a block
if !snap.ValidatorSet.HasAddress(signer) {
// Check the UnauthorizedSignerError.Error() msg to see why we pass number-1
return &UnauthorizedSignerError{header.Hash(), number, signer.Bytes()}
return &UnauthorizedSignerError{number, signer.Bytes()}
}

successionNumber, err := snap.GetSignerSuccessionNumber(signer)
Expand Down
2 changes: 0 additions & 2 deletions consensus/bor/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"time"

libcommon "github.com/ledgerwatch/erigon-lib/common"
"github.com/ledgerwatch/erigon/consensus/bor/clerk"
)

Expand Down Expand Up @@ -68,7 +67,6 @@ func (e *UnauthorizedProposerError) Error() string {

// UnauthorizedSignerError is returned if a header is [being] signed by an unauthorized entity.
type UnauthorizedSignerError struct {
Hash libcommon.Hash
Number uint64
Signer []byte
}
Expand Down
12 changes: 5 additions & 7 deletions consensus/bor/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
lru "github.com/hashicorp/golang-lru/arc/v2"
"github.com/ledgerwatch/erigon-lib/chain"
"github.com/ledgerwatch/erigon-lib/common"
libcommon "github.com/ledgerwatch/erigon-lib/common"
"github.com/ledgerwatch/erigon-lib/kv"
"github.com/ledgerwatch/erigon/consensus/bor/valset"
"github.com/ledgerwatch/erigon/core/types"
Expand Down Expand Up @@ -160,7 +159,7 @@ func (s *Snapshot) Apply(parent *types.Header, headers []*types.Header, logger l

// check if signer is in validator set
if !snap.ValidatorSet.HasAddress(signer) {
return snap, &UnauthorizedSignerError{header.Hash(), number, signer.Bytes()}
return snap, &UnauthorizedSignerError{number, signer.Bytes()}
}
if succession, err = snap.GetSignerSuccessionNumber(signer); err != nil {
return snap, err
Expand Down Expand Up @@ -190,14 +189,13 @@ func (s *Snapshot) Apply(parent *types.Header, headers []*types.Header, logger l
}

if number > 64 && !validSigner {
return snap, &UnauthorizedSignerError{header.Hash(), number, signer.Bytes()}
return snap, &UnauthorizedSignerError{number, signer.Bytes()}
}
parent = header
snap.Number = number
snap.Hash = header.Hash()
}

snap.Number += uint64(len(headers))
snap.Hash = headers[len(headers)-1].Hash()

return snap, nil
}

Expand All @@ -214,7 +212,7 @@ func (s *Snapshot) GetSignerSuccessionNumber(signer common.Address) (int, error)
signerIndex, _ := s.ValidatorSet.GetByAddress(signer)

if signerIndex == -1 {
return -1, &UnauthorizedSignerError{libcommon.Hash{}, s.Number + 1, signer.Bytes()}
return -1, &UnauthorizedSignerError{s.Number + 1, signer.Bytes()}
}

tempIndex := signerIndex
Expand Down
13 changes: 11 additions & 2 deletions eth/stagedsync/stage_bor_heimdall.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

lru "github.com/hashicorp/golang-lru/arc/v2"
"github.com/ledgerwatch/erigon-lib/chain"
"github.com/ledgerwatch/erigon-lib/common"
libcommon "github.com/ledgerwatch/erigon-lib/common"
"github.com/ledgerwatch/erigon-lib/kv"
"github.com/ledgerwatch/erigon/accounts/abi"
Expand Down Expand Up @@ -543,8 +544,16 @@ func persistValidatorSets(
if len(headers) > 0 {
var err error
if snap, err = snap.Apply(parent, headers, logger); err != nil {
if signErr, ok := err.(*bor.UnauthorizedSignerError); ok {
u.UnwindTo(signErr.Number-1, signErr.Hash)
if snap != nil {
var badHash common.Hash
for _, header := range headers {
if header.Number.Uint64() == snap.Number+1 {
badHash = header.Hash()
break
}
}
u.UnwindTo(snap.Number, badHash)
logger.Error("Hey", "number", snap.Number, "badHash", badHash, "err", err)
} else {
return fmt.Errorf("snap.Apply %d, headers %d-%d: %w", blockNum, headers[0].Number.Uint64(), headers[len(headers)-1].Number.Uint64(), err)
}
Expand Down