Skip to content

Commit 1942fef

Browse files
authored
Merge branch 'ethereum:master' into portal
2 parents 2d9017e + 865e1e9 commit 1942fef

File tree

44 files changed

+149
-105
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+149
-105
lines changed

cmd/era/main.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package main
1818

1919
import (
2020
"encoding/json"
21+
"errors"
2122
"fmt"
2223
"math/big"
2324
"os"
@@ -182,7 +183,7 @@ func open(ctx *cli.Context, epoch uint64) (*era.Era, error) {
182183
// that the accumulator matches the expected value.
183184
func verify(ctx *cli.Context) error {
184185
if ctx.Args().Len() != 1 {
185-
return fmt.Errorf("missing accumulators file")
186+
return errors.New("missing accumulators file")
186187
}
187188

188189
roots, err := readHashes(ctx.Args().First())
@@ -203,7 +204,7 @@ func verify(ctx *cli.Context) error {
203204
}
204205

205206
if len(entries) != len(roots) {
206-
return fmt.Errorf("number of era1 files should match the number of accumulator hashes")
207+
return errors.New("number of era1 files should match the number of accumulator hashes")
207208
}
208209

209210
// Verify each epoch matches the expected root.
@@ -308,7 +309,7 @@ func checkAccumulator(e *era.Era) error {
308309
func readHashes(f string) ([]common.Hash, error) {
309310
b, err := os.ReadFile(f)
310311
if err != nil {
311-
return nil, fmt.Errorf("unable to open accumulators file")
312+
return nil, errors.New("unable to open accumulators file")
312313
}
313314
s := strings.Split(string(b), "\n")
314315
// Remove empty last element, if present.

cmd/geth/chaincmd.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ func importHistory(ctx *cli.Context) error {
444444
return fmt.Errorf("no era1 files found in %s", dir)
445445
}
446446
if len(networks) > 1 {
447-
return fmt.Errorf("multiple networks found, use a network flag to specify desired network")
447+
return errors.New("multiple networks found, use a network flag to specify desired network")
448448
}
449449
network = networks[0]
450450
}
@@ -514,13 +514,10 @@ func importPreimages(ctx *cli.Context) error {
514514
return nil
515515
}
516516

517-
func parseDumpConfig(ctx *cli.Context, stack *node.Node) (*state.DumpConfig, ethdb.Database, common.Hash, error) {
518-
db := utils.MakeChainDatabase(ctx, stack, true)
519-
defer db.Close()
520-
517+
func parseDumpConfig(ctx *cli.Context, stack *node.Node, db ethdb.Database) (*state.DumpConfig, common.Hash, error) {
521518
var header *types.Header
522519
if ctx.NArg() > 1 {
523-
return nil, nil, common.Hash{}, fmt.Errorf("expected 1 argument (number or hash), got %d", ctx.NArg())
520+
return nil, common.Hash{}, fmt.Errorf("expected 1 argument (number or hash), got %d", ctx.NArg())
524521
}
525522
if ctx.NArg() == 1 {
526523
arg := ctx.Args().First()
@@ -529,25 +526,25 @@ func parseDumpConfig(ctx *cli.Context, stack *node.Node) (*state.DumpConfig, eth
529526
if number := rawdb.ReadHeaderNumber(db, hash); number != nil {
530527
header = rawdb.ReadHeader(db, hash, *number)
531528
} else {
532-
return nil, nil, common.Hash{}, fmt.Errorf("block %x not found", hash)
529+
return nil, common.Hash{}, fmt.Errorf("block %x not found", hash)
533530
}
534531
} else {
535532
number, err := strconv.ParseUint(arg, 10, 64)
536533
if err != nil {
537-
return nil, nil, common.Hash{}, err
534+
return nil, common.Hash{}, err
538535
}
539536
if hash := rawdb.ReadCanonicalHash(db, number); hash != (common.Hash{}) {
540537
header = rawdb.ReadHeader(db, hash, number)
541538
} else {
542-
return nil, nil, common.Hash{}, fmt.Errorf("header for block %d not found", number)
539+
return nil, common.Hash{}, fmt.Errorf("header for block %d not found", number)
543540
}
544541
}
545542
} else {
546543
// Use latest
547544
header = rawdb.ReadHeadHeader(db)
548545
}
549546
if header == nil {
550-
return nil, nil, common.Hash{}, errors.New("no head block found")
547+
return nil, common.Hash{}, errors.New("no head block found")
551548
}
552549
startArg := common.FromHex(ctx.String(utils.StartKeyFlag.Name))
553550
var start common.Hash
@@ -559,7 +556,7 @@ func parseDumpConfig(ctx *cli.Context, stack *node.Node) (*state.DumpConfig, eth
559556
start = crypto.Keccak256Hash(startArg)
560557
log.Info("Converting start-address to hash", "address", common.BytesToAddress(startArg), "hash", start.Hex())
561558
default:
562-
return nil, nil, common.Hash{}, fmt.Errorf("invalid start argument: %x. 20 or 32 hex-encoded bytes required", startArg)
559+
return nil, common.Hash{}, fmt.Errorf("invalid start argument: %x. 20 or 32 hex-encoded bytes required", startArg)
563560
}
564561
var conf = &state.DumpConfig{
565562
SkipCode: ctx.Bool(utils.ExcludeCodeFlag.Name),
@@ -571,14 +568,17 @@ func parseDumpConfig(ctx *cli.Context, stack *node.Node) (*state.DumpConfig, eth
571568
log.Info("State dump configured", "block", header.Number, "hash", header.Hash().Hex(),
572569
"skipcode", conf.SkipCode, "skipstorage", conf.SkipStorage,
573570
"start", hexutil.Encode(conf.Start), "limit", conf.Max)
574-
return conf, db, header.Root, nil
571+
return conf, header.Root, nil
575572
}
576573

577574
func dump(ctx *cli.Context) error {
578575
stack, _ := makeConfigNode(ctx)
579576
defer stack.Close()
580577

581-
conf, db, root, err := parseDumpConfig(ctx, stack)
578+
db := utils.MakeChainDatabase(ctx, stack, true)
579+
defer db.Close()
580+
581+
conf, root, err := parseDumpConfig(ctx, stack, db)
582582
if err != nil {
583583
return err
584584
}

cmd/geth/snapshot.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,10 @@ func dumpState(ctx *cli.Context) error {
541541
stack, _ := makeConfigNode(ctx)
542542
defer stack.Close()
543543

544-
conf, db, root, err := parseDumpConfig(ctx, stack)
544+
db := utils.MakeChainDatabase(ctx, stack, true)
545+
defer db.Close()
546+
547+
conf, root, err := parseDumpConfig(ctx, stack, db)
545548
if err != nil {
546549
return err
547550
}

cmd/utils/cmd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ func readList(filename string) ([]string, error) {
245245
// starting from genesis.
246246
func ImportHistory(chain *core.BlockChain, db ethdb.Database, dir string, network string) error {
247247
if chain.CurrentSnapBlock().Number.BitLen() != 0 {
248-
return fmt.Errorf("history import only supported when starting from genesis")
248+
return errors.New("history import only supported when starting from genesis")
249249
}
250250
entries, err := era.ReadDir(dir, network)
251251
if err != nil {

cmd/utils/flags.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1668,6 +1668,9 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
16681668
if ctx.String(GCModeFlag.Name) == "archive" && cfg.TransactionHistory != 0 {
16691669
cfg.TransactionHistory = 0
16701670
log.Warn("Disabled transaction unindexing for archive node")
1671+
1672+
cfg.StateScheme = rawdb.HashScheme
1673+
log.Warn("Forcing hash state-scheme for archive mode")
16711674
}
16721675
if ctx.IsSet(CacheFlag.Name) || ctx.IsSet(CacheTrieFlag.Name) {
16731676
cfg.TrieCleanCache = ctx.Int(CacheFlag.Name) * ctx.Int(CacheTrieFlag.Name) / 100

core/rawdb/accessors_trie.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ func ReadStateScheme(db ethdb.Reader) string {
315315
// the stored state.
316316
//
317317
// - If the provided scheme is none, use the scheme consistent with persistent
318-
// state, or fallback to hash-based scheme if state is empty.
318+
// state, or fallback to path-based scheme if state is empty.
319319
//
320320
// - If the provided scheme is hash, use hash-based scheme or error out if not
321321
// compatible with persistent state scheme.
@@ -329,10 +329,8 @@ func ParseStateScheme(provided string, disk ethdb.Database) (string, error) {
329329
stored := ReadStateScheme(disk)
330330
if provided == "" {
331331
if stored == "" {
332-
// use default scheme for empty database, flip it when
333-
// path mode is chosen as default
334-
log.Info("State schema set to default", "scheme", "hash")
335-
return HashScheme, nil
332+
log.Info("State schema set to default", "scheme", "path")
333+
return PathScheme, nil // use default scheme for empty database
336334
}
337335
log.Info("State scheme set to already existing", "scheme", stored)
338336
return stored, nil // reuse scheme of persistent scheme

core/rawdb/schema.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ var (
113113
skeletonHeaderPrefix = []byte("S") // skeletonHeaderPrefix + num (uint64 big endian) -> header
114114

115115
// Path-based storage scheme of merkle patricia trie.
116-
trieNodeAccountPrefix = []byte("A") // trieNodeAccountPrefix + hexPath -> trie node
117-
trieNodeStoragePrefix = []byte("O") // trieNodeStoragePrefix + accountHash + hexPath -> trie node
116+
TrieNodeAccountPrefix = []byte("A") // TrieNodeAccountPrefix + hexPath -> trie node
117+
TrieNodeStoragePrefix = []byte("O") // TrieNodeStoragePrefix + accountHash + hexPath -> trie node
118118
stateIDPrefix = []byte("L") // stateIDPrefix + state root -> state id
119119

120120
PreimagePrefix = []byte("secure-key-") // PreimagePrefix + hash -> preimage
@@ -265,15 +265,15 @@ func stateIDKey(root common.Hash) []byte {
265265
return append(stateIDPrefix, root.Bytes()...)
266266
}
267267

268-
// accountTrieNodeKey = trieNodeAccountPrefix + nodePath.
268+
// accountTrieNodeKey = TrieNodeAccountPrefix + nodePath.
269269
func accountTrieNodeKey(path []byte) []byte {
270-
return append(trieNodeAccountPrefix, path...)
270+
return append(TrieNodeAccountPrefix, path...)
271271
}
272272

273-
// storageTrieNodeKey = trieNodeStoragePrefix + accountHash + nodePath.
273+
// storageTrieNodeKey = TrieNodeStoragePrefix + accountHash + nodePath.
274274
func storageTrieNodeKey(accountHash common.Hash, path []byte) []byte {
275-
buf := make([]byte, len(trieNodeStoragePrefix)+common.HashLength+len(path))
276-
n := copy(buf, trieNodeStoragePrefix)
275+
buf := make([]byte, len(TrieNodeStoragePrefix)+common.HashLength+len(path))
276+
n := copy(buf, TrieNodeStoragePrefix)
277277
n += copy(buf[n:], accountHash.Bytes())
278278
copy(buf[n:], path)
279279
return buf
@@ -294,16 +294,16 @@ func IsLegacyTrieNode(key []byte, val []byte) bool {
294294
// account trie node in path-based state scheme, and returns the resolved
295295
// node path if so.
296296
func ResolveAccountTrieNodeKey(key []byte) (bool, []byte) {
297-
if !bytes.HasPrefix(key, trieNodeAccountPrefix) {
297+
if !bytes.HasPrefix(key, TrieNodeAccountPrefix) {
298298
return false, nil
299299
}
300300
// The remaining key should only consist a hex node path
301301
// whose length is in the range 0 to 64 (64 is excluded
302302
// since leaves are always wrapped with shortNode).
303-
if len(key) >= len(trieNodeAccountPrefix)+common.HashLength*2 {
303+
if len(key) >= len(TrieNodeAccountPrefix)+common.HashLength*2 {
304304
return false, nil
305305
}
306-
return true, key[len(trieNodeAccountPrefix):]
306+
return true, key[len(TrieNodeAccountPrefix):]
307307
}
308308

309309
// IsAccountTrieNode reports whether a provided database entry is an account
@@ -317,20 +317,20 @@ func IsAccountTrieNode(key []byte) bool {
317317
// trie node in path-based state scheme, and returns the resolved account hash
318318
// and node path if so.
319319
func ResolveStorageTrieNode(key []byte) (bool, common.Hash, []byte) {
320-
if !bytes.HasPrefix(key, trieNodeStoragePrefix) {
320+
if !bytes.HasPrefix(key, TrieNodeStoragePrefix) {
321321
return false, common.Hash{}, nil
322322
}
323323
// The remaining key consists of 2 parts:
324324
// - 32 bytes account hash
325325
// - hex node path whose length is in the range 0 to 64
326-
if len(key) < len(trieNodeStoragePrefix)+common.HashLength {
326+
if len(key) < len(TrieNodeStoragePrefix)+common.HashLength {
327327
return false, common.Hash{}, nil
328328
}
329-
if len(key) >= len(trieNodeStoragePrefix)+common.HashLength+common.HashLength*2 {
329+
if len(key) >= len(TrieNodeStoragePrefix)+common.HashLength+common.HashLength*2 {
330330
return false, common.Hash{}, nil
331331
}
332-
accountHash := common.BytesToHash(key[len(trieNodeStoragePrefix) : len(trieNodeStoragePrefix)+common.HashLength])
333-
return true, accountHash, key[len(trieNodeStoragePrefix)+common.HashLength:]
332+
accountHash := common.BytesToHash(key[len(TrieNodeStoragePrefix) : len(TrieNodeStoragePrefix)+common.HashLength])
333+
return true, accountHash, key[len(TrieNodeStoragePrefix)+common.HashLength:]
334334
}
335335

336336
// IsStorageTrieNode reports whether a provided database entry is a storage

core/txpool/errors.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,10 @@ var (
5454
// ErrFutureReplacePending is returned if a future transaction replaces a pending
5555
// one. Future transactions should only be able to replace other future transactions.
5656
ErrFutureReplacePending = errors.New("future transaction tries to replace pending")
57+
58+
// ErrAlreadyReserved is returned if the sender address has a pending transaction
59+
// in a different subpool. For example, this error is returned in response to any
60+
// input transaction of non-blob type when a blob transaction from this sender
61+
// remains pending (and vice-versa).
62+
ErrAlreadyReserved = errors.New("address already reserved")
5763
)

core/txpool/legacypool/journal.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,12 @@ func (journal *journal) rotate(all map[common.Address]types.Transactions) error
164164
return err
165165
}
166166
journal.writer = sink
167-
log.Info("Regenerated local transaction journal", "transactions", journaled, "accounts", len(all))
167+
168+
logger := log.Info
169+
if len(all) == 0 {
170+
logger = log.Debug
171+
}
172+
logger("Regenerated local transaction journal", "transactions", journaled, "accounts", len(all))
168173

169174
return nil
170175
}

core/txpool/txpool.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func (p *TxPool) reserver(id int, subpool SubPool) AddressReserver {
122122
log.Error("pool attempted to reserve already-owned address", "address", addr)
123123
return nil // Ignore fault to give the pool a chance to recover while the bug gets fixed
124124
}
125-
return errors.New("address already reserved")
125+
return ErrAlreadyReserved
126126
}
127127
p.reservations[addr] = subpool
128128
if metrics.Enabled {

0 commit comments

Comments
 (0)