Skip to content

Commit bfaa203

Browse files
authored
Merge branch 'ethereum:master' into master
2 parents 89fb050 + 997f1c4 commit bfaa203

File tree

28 files changed

+572
-155
lines changed

28 files changed

+572
-155
lines changed

cmd/abigen/main.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ var (
5555
}
5656
jsonFlag = cli.StringFlag{
5757
Name: "combined-json",
58-
Usage: "Path to the combined-json file generated by compiler",
58+
Usage: "Path to the combined-json file generated by compiler, - for STDIN",
5959
}
6060
excFlag = cli.StringFlag{
6161
Name: "exc",
@@ -165,9 +165,18 @@ func abigen(c *cli.Context) error {
165165
var contracts map[string]*compiler.Contract
166166

167167
if c.GlobalIsSet(jsonFlag.Name) {
168-
jsonOutput, err := os.ReadFile(c.GlobalString(jsonFlag.Name))
168+
var (
169+
input = c.GlobalString(jsonFlag.Name)
170+
jsonOutput []byte
171+
err error
172+
)
173+
if input == "-" {
174+
jsonOutput, err = io.ReadAll(os.Stdin)
175+
} else {
176+
jsonOutput, err = os.ReadFile(input)
177+
}
169178
if err != nil {
170-
utils.Fatalf("Failed to read combined-json from compiler: %v", err)
179+
utils.Fatalf("Failed to read combined-json: %v", err)
171180
}
172181
contracts, err = compiler.ParseCombinedJSON(jsonOutput, "", "", "", "")
173182
if err != nil {

cmd/geth/config.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) {
164164
}
165165
backend, eth := utils.RegisterEthService(stack, &cfg.Eth)
166166
// Warn users to migrate if they have a legacy freezer format.
167-
if eth != nil {
167+
if eth != nil && !ctx.GlobalIsSet(utils.IgnoreLegacyReceiptsFlag.Name) {
168168
firstIdx := uint64(0)
169169
// Hack to speed up check for mainnet because we know
170170
// the first non-empty block.
@@ -176,7 +176,8 @@ func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) {
176176
if err != nil {
177177
log.Error("Failed to check db for legacy receipts", "err", err)
178178
} else if isLegacy {
179-
log.Warn("Database has receipts with a legacy format. Please run `geth db freezer-migrate`.")
179+
stack.Close()
180+
utils.Fatalf("Database has receipts with a legacy format. Please run `geth db freezer-migrate`.")
180181
}
181182
}
182183

cmd/geth/dbcmd.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ func checkStateContent(ctx *cli.Context) error {
307307
start []byte
308308
)
309309
if ctx.NArg() > 1 {
310-
return fmt.Errorf("Max 1 argument: %v", ctx.Command.ArgsUsage)
310+
return fmt.Errorf("max 1 argument: %v", ctx.Command.ArgsUsage)
311311
}
312312
if ctx.NArg() > 0 {
313313
if d, err := hexutil.Decode(ctx.Args().First()); err != nil {
@@ -332,8 +332,8 @@ func checkStateContent(ctx *cli.Context) error {
332332
)
333333
for it.Next() {
334334
count++
335-
v := it.Value()
336335
k := it.Key()
336+
v := it.Value()
337337
hasher.Reset()
338338
hasher.Write(v)
339339
hasher.Read(got)

cmd/geth/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ var (
151151
utils.GpoMaxGasPriceFlag,
152152
utils.GpoIgnoreGasPriceFlag,
153153
utils.MinerNotifyFullFlag,
154+
utils.IgnoreLegacyReceiptsFlag,
154155
configFileFlag,
155156
}, utils.NetworkFlags, utils.DatabasePathFlags)
156157

cmd/geth/snapshot.go

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ data, and verifies that all snapshot storage data has a corresponding account.
105105
},
106106
{
107107
Name: "traverse-state",
108-
Usage: "Traverse the state with given root hash for verification",
108+
Usage: "Traverse the state with given root hash and perform quick verification",
109109
ArgsUsage: "<root>",
110110
Action: utils.MigrateFlags(traverseState),
111111
Category: "MISCELLANEOUS COMMANDS",
@@ -121,7 +121,7 @@ It's also usable without snapshot enabled.
121121
},
122122
{
123123
Name: "traverse-rawstate",
124-
Usage: "Traverse the state with given root hash for verification",
124+
Usage: "Traverse the state with given root hash and perform detailed verification",
125125
ArgsUsage: "<root>",
126126
Action: utils.MigrateFlags(traverseRawState),
127127
Category: "MISCELLANEOUS COMMANDS",
@@ -367,6 +367,8 @@ func traverseRawState(ctx *cli.Context) error {
367367
codes int
368368
lastReport time.Time
369369
start = time.Now()
370+
hasher = crypto.NewKeccakState()
371+
got = make([]byte, 32)
370372
)
371373
accIter := t.NodeIterator(nil)
372374
for accIter.Next(true) {
@@ -376,10 +378,18 @@ func traverseRawState(ctx *cli.Context) error {
376378
// Check the present for non-empty hash node(embedded node doesn't
377379
// have their own hash).
378380
if node != (common.Hash{}) {
379-
if !rawdb.HasTrieNode(chaindb, node) {
381+
blob := rawdb.ReadTrieNode(chaindb, node)
382+
if len(blob) == 0 {
380383
log.Error("Missing trie node(account)", "hash", node)
381384
return errors.New("missing account")
382385
}
386+
hasher.Reset()
387+
hasher.Write(blob)
388+
hasher.Read(got)
389+
if !bytes.Equal(got, node.Bytes()) {
390+
log.Error("Invalid trie node(account)", "hash", node.Hex(), "value", blob)
391+
return errors.New("invalid account node")
392+
}
383393
}
384394
// If it's a leaf node, yes we are touching an account,
385395
// dig into the storage trie further.
@@ -404,10 +414,18 @@ func traverseRawState(ctx *cli.Context) error {
404414
// Check the present for non-empty hash node(embedded node doesn't
405415
// have their own hash).
406416
if node != (common.Hash{}) {
407-
if !rawdb.HasTrieNode(chaindb, node) {
417+
blob := rawdb.ReadTrieNode(chaindb, node)
418+
if len(blob) == 0 {
408419
log.Error("Missing trie node(storage)", "hash", node)
409420
return errors.New("missing storage")
410421
}
422+
hasher.Reset()
423+
hasher.Write(blob)
424+
hasher.Read(got)
425+
if !bytes.Equal(got, node.Bytes()) {
426+
log.Error("Invalid trie node(storage)", "hash", node.Hex(), "value", blob)
427+
return errors.New("invalid storage node")
428+
}
411429
}
412430
// Bump the counter if it's leaf node.
413431
if storageIter.Leaf() {

cmd/geth/usage.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ var AppHelpFlagGroups = []flags.FlagGroup{
227227
Flags: []cli.Flag{
228228
utils.SnapshotFlag,
229229
utils.BloomFilterSizeFlag,
230+
utils.IgnoreLegacyReceiptsFlag,
230231
cli.HelpFlag,
231232
},
232233
},

cmd/utils/flags.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,10 @@ var (
566566
Name: "nocompaction",
567567
Usage: "Disables db compaction after import",
568568
}
569+
IgnoreLegacyReceiptsFlag = cli.BoolFlag{
570+
Name: "ignore-legacy-receipts",
571+
Usage: "Geth will start up even if there are legacy receipts in freezer",
572+
}
569573
// RPC settings
570574
IPCDisabledFlag = cli.BoolFlag{
571575
Name: "ipcdisable",

consensus/clique/clique.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ type Clique struct {
180180

181181
signer common.Address // Ethereum address of the signing key
182182
signFn SignerFn // Signer function to authorize hashes with
183-
lock sync.RWMutex // Protects the signer fields
183+
lock sync.RWMutex // Protects the signer and proposals fields
184184

185185
// The fields below are for testing only
186186
fakeDiff bool // Skip difficulty verifications
@@ -507,9 +507,8 @@ func (c *Clique) Prepare(chain consensus.ChainHeaderReader, header *types.Header
507507
if err != nil {
508508
return err
509509
}
510+
c.lock.RLock()
510511
if number%c.config.Epoch != 0 {
511-
c.lock.RLock()
512-
513512
// Gather all the proposals that make sense voting on
514513
addresses := make([]common.Address, 0, len(c.proposals))
515514
for address, authorize := range c.proposals {
@@ -526,10 +525,14 @@ func (c *Clique) Prepare(chain consensus.ChainHeaderReader, header *types.Header
526525
copy(header.Nonce[:], nonceDropVote)
527526
}
528527
}
529-
c.lock.RUnlock()
530528
}
529+
530+
// Copy signer protected by mutex to avoid race condition
531+
signer := c.signer
532+
c.lock.RUnlock()
533+
531534
// Set the correct difficulty
532-
header.Difficulty = calcDifficulty(snap, c.signer)
535+
header.Difficulty = calcDifficulty(snap, signer)
533536

534537
// Ensure the extra data has all its components
535538
if len(header.Extra) < extraVanity {
@@ -666,7 +669,10 @@ func (c *Clique) CalcDifficulty(chain consensus.ChainHeaderReader, time uint64,
666669
if err != nil {
667670
return nil
668671
}
669-
return calcDifficulty(snap, c.signer)
672+
c.lock.RLock()
673+
signer := c.signer
674+
c.lock.RUnlock()
675+
return calcDifficulty(snap, signer)
670676
}
671677

672678
func calcDifficulty(snap *Snapshot, signer common.Address) *big.Int {

consensus/misc/eip1559.go

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -58,36 +58,36 @@ func CalcBaseFee(config *params.ChainConfig, parent *types.Header) *big.Int {
5858
return new(big.Int).SetUint64(params.InitialBaseFee)
5959
}
6060

61-
var (
62-
parentGasTarget = parent.GasLimit / params.ElasticityMultiplier
63-
parentGasTargetBig = new(big.Int).SetUint64(parentGasTarget)
64-
baseFeeChangeDenominator = new(big.Int).SetUint64(params.BaseFeeChangeDenominator)
65-
)
61+
parentGasTarget := parent.GasLimit / params.ElasticityMultiplier
6662
// If the parent gasUsed is the same as the target, the baseFee remains unchanged.
6763
if parent.GasUsed == parentGasTarget {
6864
return new(big.Int).Set(parent.BaseFee)
6965
}
66+
67+
var (
68+
num = new(big.Int)
69+
denom = new(big.Int)
70+
)
71+
7072
if parent.GasUsed > parentGasTarget {
7173
// If the parent block used more gas than its target, the baseFee should increase.
72-
gasUsedDelta := new(big.Int).SetUint64(parent.GasUsed - parentGasTarget)
73-
x := new(big.Int).Mul(parent.BaseFee, gasUsedDelta)
74-
y := x.Div(x, parentGasTargetBig)
75-
baseFeeDelta := math.BigMax(
76-
x.Div(y, baseFeeChangeDenominator),
77-
common.Big1,
78-
)
74+
// max(1, parentBaseFee * gasUsedDelta / parentGasTarget / baseFeeChangeDenominator)
75+
num.SetUint64(parent.GasUsed - parentGasTarget)
76+
num.Mul(num, parent.BaseFee)
77+
num.Div(num, denom.SetUint64(parentGasTarget))
78+
num.Div(num, denom.SetUint64(params.BaseFeeChangeDenominator))
79+
baseFeeDelta := math.BigMax(num, common.Big1)
7980

80-
return x.Add(parent.BaseFee, baseFeeDelta)
81+
return num.Add(parent.BaseFee, baseFeeDelta)
8182
} else {
8283
// Otherwise if the parent block used less gas than its target, the baseFee should decrease.
83-
gasUsedDelta := new(big.Int).SetUint64(parentGasTarget - parent.GasUsed)
84-
x := new(big.Int).Mul(parent.BaseFee, gasUsedDelta)
85-
y := x.Div(x, parentGasTargetBig)
86-
baseFeeDelta := x.Div(y, baseFeeChangeDenominator)
84+
// max(0, parentBaseFee * gasUsedDelta / parentGasTarget / baseFeeChangeDenominator)
85+
num.SetUint64(parentGasTarget - parent.GasUsed)
86+
num.Mul(num, parent.BaseFee)
87+
num.Div(num, denom.SetUint64(parentGasTarget))
88+
num.Div(num, denom.SetUint64(params.BaseFeeChangeDenominator))
89+
baseFee := num.Sub(parent.BaseFee, num)
8790

88-
return math.BigMax(
89-
x.Sub(parent.BaseFee, baseFeeDelta),
90-
common.Big0,
91-
)
91+
return math.BigMax(baseFee, common.Big0)
9292
}
9393
}

contracts/checkpointoracle/oracle.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
// Package checkpointoracle is a an on-chain light client checkpoint oracle.
1818
package checkpointoracle
1919

20-
//go:generate go run ../../cmd/abigen --sol contract/oracle.sol --pkg contract --out contract/oracle.go
20+
//go:generate solc contract/oracle.sol --combined-json bin,bin-runtime,srcmap,srcmap-runtime,abi,userdoc,devdoc,metadata,hashes --optimize -o ./ --overwrite
21+
//go:generate go run ../../cmd/abigen --pkg contract --out contract/oracle.go --combined-json ./combined.json
2122

2223
import (
2324
"errors"

0 commit comments

Comments
 (0)