Merge branch 'ethereum:master' into gethintegration

This commit is contained in:
Chen Kai 2025-04-29 20:15:20 +08:00 committed by GitHub
commit bd329c7e97
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 63 additions and 17 deletions

View file

@ -131,7 +131,7 @@ type executionPayloadEnvelopeMarshaling struct {
type PayloadStatusV1 struct { type PayloadStatusV1 struct {
Status string `json:"status"` Status string `json:"status"`
Witness *hexutil.Bytes `json:"witness"` Witness *hexutil.Bytes `json:"witness,omitempty"`
LatestValidHash *common.Hash `json:"latestValidHash"` LatestValidHash *common.Hash `json:"latestValidHash"`
ValidationError *string `json:"validationError"` ValidationError *string `json:"validationError"`
} }

View file

@ -365,6 +365,9 @@ func SetupGenesisBlockWithOverride(db ethdb.Database, triedb *triedb.Database, g
return nil, common.Hash{}, nil, errors.New("missing head header") return nil, common.Hash{}, nil, errors.New("missing head header")
} }
newCfg := genesis.chainConfigOrDefault(ghash, storedCfg) newCfg := genesis.chainConfigOrDefault(ghash, storedCfg)
if err := overrides.apply(newCfg); err != nil {
return nil, common.Hash{}, nil, err
}
// Sanity-check the new configuration. // Sanity-check the new configuration.
if err := newCfg.CheckConfigForkOrder(); err != nil { if err := newCfg.CheckConfigForkOrder(); err != nil {

View file

@ -1494,22 +1494,22 @@ func (pool *LegacyPool) promoteExecutables(accounts []common.Address) []*types.T
// equal number for all for accounts with many pending transactions. // equal number for all for accounts with many pending transactions.
func (pool *LegacyPool) truncatePending() { func (pool *LegacyPool) truncatePending() {
pending := uint64(0) pending := uint64(0)
for _, list := range pool.pending {
pending += uint64(list.Len()) // Assemble a spam order to penalize large transactors first
spammers := prque.New[uint64, common.Address](nil)
for addr, list := range pool.pending {
// Only evict transactions from high rollers
length := uint64(list.Len())
pending += length
if length > pool.config.AccountSlots {
spammers.Push(addr, length)
}
} }
if pending <= pool.config.GlobalSlots { if pending <= pool.config.GlobalSlots {
return return
} }
pendingBeforeCap := pending pendingBeforeCap := pending
// Assemble a spam order to penalize large transactors first
spammers := prque.New[int64, common.Address](nil)
for addr, list := range pool.pending {
// Only evict transactions from high rollers
if uint64(list.Len()) > pool.config.AccountSlots {
spammers.Push(addr, int64(list.Len()))
}
}
// Gradually drop transactions from offenders // Gradually drop transactions from offenders
offenders := []common.Address{} offenders := []common.Address{}
for pending > pool.config.GlobalSlots && !spammers.Empty() { for pending > pool.config.GlobalSlots && !spammers.Empty() {

View file

@ -373,8 +373,11 @@ func (api *ConsensusAPI) forkchoiceUpdated(update engine.ForkchoiceStateV1, payl
} }
valid := func(id *engine.PayloadID) engine.ForkChoiceResponse { valid := func(id *engine.PayloadID) engine.ForkChoiceResponse {
return engine.ForkChoiceResponse{ return engine.ForkChoiceResponse{
PayloadStatus: engine.PayloadStatusV1{Status: engine.VALID, LatestValidHash: &update.HeadBlockHash}, PayloadStatus: engine.PayloadStatusV1{
PayloadID: id, Status: engine.VALID,
LatestValidHash: &update.HeadBlockHash,
},
PayloadID: id,
} }
} }
if rawdb.ReadCanonicalHash(api.eth.ChainDb(), block.NumberU64()) != update.HeadBlockHash { if rawdb.ReadCanonicalHash(api.eth.ChainDb(), block.NumberU64()) != update.HeadBlockHash {

View file

@ -485,10 +485,18 @@ func VerifyRangeProof(rootHash common.Hash, firstKey []byte, keys [][]byte, valu
if len(keys) != len(values) { if len(keys) != len(values) {
return false, fmt.Errorf("inconsistent proof data, keys: %d, values: %d", len(keys), len(values)) return false, fmt.Errorf("inconsistent proof data, keys: %d, values: %d", len(keys), len(values))
} }
// Ensure the received batch is monotonic increasing and contains no deletions // Ensure the received batch is
// - monotonically increasing,
// - not expanding down prefix-paths
// - and contains no deletions
for i := 0; i < len(keys); i++ { for i := 0; i < len(keys); i++ {
if i < len(keys)-1 && bytes.Compare(keys[i], keys[i+1]) >= 0 { if i < len(keys)-1 {
return false, errors.New("range is not monotonically increasing") if bytes.Compare(keys[i], keys[i+1]) >= 0 {
return false, errors.New("range is not monotonically increasing")
}
if bytes.HasPrefix(keys[i+1], keys[i]) {
return false, errors.New("range contains path prefixes")
}
} }
if len(values[i]) == 0 { if len(values[i]) == 0 {
return false, errors.New("range contains deletion") return false, errors.New("range contains deletion")

View file

@ -1000,3 +1000,35 @@ func TestRangeProofKeysWithSharedPrefix(t *testing.T) {
t.Error("expected more to be false") t.Error("expected more to be false")
} }
} }
// TestRangeProofErrors tests a few cases where the prover is supposed
// to exit with errors
func TestRangeProofErrors(t *testing.T) {
// Different number of keys to values
_, err := VerifyRangeProof((common.Hash{}), []byte{}, make([][]byte, 5), make([][]byte, 4), nil)
if have, want := err.Error(), "inconsistent proof data, keys: 5, values: 4"; have != want {
t.Fatalf("wrong error, have %q, want %q", err.Error(), want)
}
// Non-increasing paths
_, err = VerifyRangeProof((common.Hash{}), []byte{},
[][]byte{[]byte{2, 1}, []byte{2, 1}}, make([][]byte, 2), nil)
if have, want := err.Error(), "range is not monotonically increasing"; have != want {
t.Fatalf("wrong error, have %q, want %q", err.Error(), want)
}
// A prefixed path is never motivated. Inserting the second element will
// require rewriting/overwriting the previous value-node, thus can only
// happen if the data is corrupt.
_, err = VerifyRangeProof((common.Hash{}), []byte{},
[][]byte{[]byte{2, 1}, []byte{2, 1, 2}},
[][]byte{[]byte{1}, []byte{1}}, nil)
if have, want := err.Error(), "range contains path prefixes"; have != want {
t.Fatalf("wrong error, have %q, want %q", err.Error(), want)
}
// Empty values (deletions)
_, err = VerifyRangeProof((common.Hash{}), []byte{},
[][]byte{[]byte{2, 1}, []byte{2, 2}},
[][]byte{[]byte{1}, []byte{}}, nil)
if have, want := err.Error(), "range contains deletion"; have != want {
t.Fatalf("wrong error, have %q, want %q", err.Error(), want)
}
}