Merge commit 'c3d9ca62c' into merge/geth-v1.13.6

This commit is contained in:
philip-morlier 2023-12-20 09:33:18 -08:00
commit c01da155be
10 changed files with 135 additions and 39 deletions

View File

@ -9,18 +9,6 @@ jobs:
- azure-osx - azure-osx
include: include:
# This builder only tests code linters on latest version of Go
- stage: lint
os: linux
dist: bionic
go: 1.21.x
env:
- lint
git:
submodules: false # avoid cloning ethereum/tests
script:
- go run build/ci.go lint
# These builders create the Docker sub-images for multi-arch push and each # These builders create the Docker sub-images for multi-arch push and each
# will attempt to push the multi-arch image if they are the last builder # will attempt to push the multi-arch image if they are the last builder
- stage: build - stage: build

View File

@ -366,7 +366,7 @@ func doLint(cmdline []string) {
linter := downloadLinter(*cachedir) linter := downloadLinter(*cachedir)
lflags := []string{"run", "--config", ".golangci.yml"} lflags := []string{"run", "--config", ".golangci.yml"}
build.MustRunCommand(linter, append(lflags, packages...)...) build.MustRunCommandWithOutput(linter, append(lflags, packages...)...)
fmt.Println("You have achieved perfection.") fmt.Println("You have achieved perfection.")
} }

View File

@ -467,6 +467,20 @@ func (t *freezerTable) truncateHead(items uint64) error {
return nil return nil
} }
// sizeHidden returns the total data size of hidden items in the freezer table.
// This function assumes the lock is already held.
func (t *freezerTable) sizeHidden() (uint64, error) {
hidden, offset := t.itemHidden.Load(), t.itemOffset.Load()
if hidden <= offset {
return 0, nil
}
indices, err := t.getIndices(hidden-1, 1)
if err != nil {
return 0, err
}
return uint64(indices[1].offset), nil
}
// truncateTail discards any recent data before the provided threshold number. // truncateTail discards any recent data before the provided threshold number.
func (t *freezerTable) truncateTail(items uint64) error { func (t *freezerTable) truncateTail(items uint64) error {
t.lock.Lock() t.lock.Lock()
@ -495,6 +509,12 @@ func (t *freezerTable) truncateTail(items uint64) error {
newTail.unmarshalBinary(buffer) newTail.unmarshalBinary(buffer)
newTailId = newTail.filenum newTailId = newTail.filenum
} }
// Save the old size for metrics tracking. This needs to be done
// before any updates to either itemHidden or itemOffset.
oldSize, err := t.sizeNolock()
if err != nil {
return err
}
// Update the virtual tail marker and hidden these entries in table. // Update the virtual tail marker and hidden these entries in table.
t.itemHidden.Store(items) t.itemHidden.Store(items)
if err := writeMetadata(t.meta, newMetadata(items)); err != nil { if err := writeMetadata(t.meta, newMetadata(items)); err != nil {
@ -509,18 +529,12 @@ func (t *freezerTable) truncateTail(items uint64) error {
if t.tailId > newTailId { if t.tailId > newTailId {
return fmt.Errorf("invalid index, tail-file %d, item-file %d", t.tailId, newTailId) return fmt.Errorf("invalid index, tail-file %d, item-file %d", t.tailId, newTailId)
} }
// Hidden items exceed the current tail file, drop the relevant
// data files. We need to truncate, save the old size for metrics
// tracking.
oldSize, err := t.sizeNolock()
if err != nil {
return err
}
// Count how many items can be deleted from the file. // Count how many items can be deleted from the file.
var ( var (
newDeleted = items newDeleted = items
deleted = t.itemOffset.Load() deleted = t.itemOffset.Load()
) )
// Hidden items exceed the current tail file, drop the relevant data files.
for current := items - 1; current >= deleted; current -= 1 { for current := items - 1; current >= deleted; current -= 1 {
if _, err := t.index.ReadAt(buffer, int64((current-deleted+1)*indexEntrySize)); err != nil { if _, err := t.index.ReadAt(buffer, int64((current-deleted+1)*indexEntrySize)); err != nil {
return err return err
@ -680,6 +694,7 @@ func (t *freezerTable) releaseFilesBefore(num uint32, remove bool) {
func (t *freezerTable) getIndices(from, count uint64) ([]*indexEntry, error) { func (t *freezerTable) getIndices(from, count uint64) ([]*indexEntry, error) {
// Apply the table-offset // Apply the table-offset
from = from - t.itemOffset.Load() from = from - t.itemOffset.Load()
// For reading N items, we need N+1 indices. // For reading N items, we need N+1 indices.
buffer := make([]byte, (count+1)*indexEntrySize) buffer := make([]byte, (count+1)*indexEntrySize)
if _, err := t.index.ReadAt(buffer, int64(from*indexEntrySize)); err != nil { if _, err := t.index.ReadAt(buffer, int64(from*indexEntrySize)); err != nil {
@ -870,14 +885,18 @@ func (t *freezerTable) size() (uint64, error) {
return t.sizeNolock() return t.sizeNolock()
} }
// sizeNolock returns the total data size in the freezer table without obtaining // sizeNolock returns the total data size in the freezer table. This function
// the mutex first. // assumes the lock is already held.
func (t *freezerTable) sizeNolock() (uint64, error) { func (t *freezerTable) sizeNolock() (uint64, error) {
stat, err := t.index.Stat() stat, err := t.index.Stat()
if err != nil { if err != nil {
return 0, err return 0, err
} }
total := uint64(t.maxFileSize)*uint64(t.headId-t.tailId) + uint64(t.headBytes) + uint64(stat.Size()) hidden, err := t.sizeHidden()
if err != nil {
return 0, err
}
total := uint64(t.maxFileSize)*uint64(t.headId-t.tailId) + uint64(t.headBytes) + uint64(stat.Size()) - hidden
return total, nil return total, nil
} }

View File

@ -658,6 +658,13 @@ func TestFreezerOffset(t *testing.T) {
} }
} }
func assertTableSize(t *testing.T, f *freezerTable, size int) {
t.Helper()
if got, err := f.size(); got != uint64(size) {
t.Fatalf("expected size of %d bytes, got %d, err: %v", size, got, err)
}
}
func TestTruncateTail(t *testing.T) { func TestTruncateTail(t *testing.T) {
t.Parallel() t.Parallel()
rm, wm, sg := metrics.NewMeter(), metrics.NewMeter(), metrics.NewGauge() rm, wm, sg := metrics.NewMeter(), metrics.NewMeter(), metrics.NewGauge()
@ -692,6 +699,9 @@ func TestTruncateTail(t *testing.T) {
5: getChunk(20, 0xaa), 5: getChunk(20, 0xaa),
6: getChunk(20, 0x11), 6: getChunk(20, 0x11),
}) })
// maxFileSize*fileCount + headBytes + indexFileSize - hiddenBytes
expected := 20*7 + 48 - 0
assertTableSize(t, f, expected)
// truncate single element( item 0 ), deletion is only supported at file level // truncate single element( item 0 ), deletion is only supported at file level
f.truncateTail(1) f.truncateTail(1)
@ -707,6 +717,8 @@ func TestTruncateTail(t *testing.T) {
5: getChunk(20, 0xaa), 5: getChunk(20, 0xaa),
6: getChunk(20, 0x11), 6: getChunk(20, 0x11),
}) })
expected = 20*7 + 48 - 20
assertTableSize(t, f, expected)
// Reopen the table, the deletion information should be persisted as well // Reopen the table, the deletion information should be persisted as well
f.Close() f.Close()
@ -739,6 +751,8 @@ func TestTruncateTail(t *testing.T) {
5: getChunk(20, 0xaa), 5: getChunk(20, 0xaa),
6: getChunk(20, 0x11), 6: getChunk(20, 0x11),
}) })
expected = 20*5 + 36 - 0
assertTableSize(t, f, expected)
// Reopen the table, the above testing should still pass // Reopen the table, the above testing should still pass
f.Close() f.Close()
@ -760,6 +774,23 @@ func TestTruncateTail(t *testing.T) {
6: getChunk(20, 0x11), 6: getChunk(20, 0x11),
}) })
// truncate 3 more elements( item 2, 3, 4), the file 1 should be deleted
// file 2 should only contain item 5
f.truncateTail(5)
checkRetrieveError(t, f, map[uint64]error{
0: errOutOfBounds,
1: errOutOfBounds,
2: errOutOfBounds,
3: errOutOfBounds,
4: errOutOfBounds,
})
checkRetrieve(t, f, map[uint64][]byte{
5: getChunk(20, 0xaa),
6: getChunk(20, 0x11),
})
expected = 20*3 + 24 - 20
assertTableSize(t, f, expected)
// truncate all, the entire freezer should be deleted // truncate all, the entire freezer should be deleted
f.truncateTail(7) f.truncateTail(7)
checkRetrieveError(t, f, map[uint64]error{ checkRetrieveError(t, f, map[uint64]error{
@ -771,6 +802,8 @@ func TestTruncateTail(t *testing.T) {
5: errOutOfBounds, 5: errOutOfBounds,
6: errOutOfBounds, 6: errOutOfBounds,
}) })
expected = 12
assertTableSize(t, f, expected)
} }
func TestTruncateHead(t *testing.T) { func TestTruncateHead(t *testing.T) {

4
go.mod
View File

@ -63,10 +63,10 @@ require (
github.com/tyler-smith/go-bip39 v1.1.0 github.com/tyler-smith/go-bip39 v1.1.0
github.com/urfave/cli/v2 v2.25.7 github.com/urfave/cli/v2 v2.25.7
go.uber.org/automaxprocs v1.5.2 go.uber.org/automaxprocs v1.5.2
golang.org/x/crypto v0.15.0 golang.org/x/crypto v0.17.0
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa
golang.org/x/sync v0.5.0 golang.org/x/sync v0.5.0
golang.org/x/sys v0.14.0 golang.org/x/sys v0.15.0
golang.org/x/text v0.14.0 golang.org/x/text v0.14.0
golang.org/x/time v0.3.0 golang.org/x/time v0.3.0
golang.org/x/tools v0.15.0 golang.org/x/tools v0.15.0

8
go.sum
View File

@ -616,8 +616,8 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh
golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.15.0 h1:frVn1TEaCEaZcn3Tmd7Y2b5KKPaZ+I32Q2OA3kYp5TA= golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
golang.org/x/crypto v0.15.0/go.mod h1:4ChreQoLWfG3xLDer1WdlH5NdlQ3+mwnQq1YTKY+72g= golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
@ -776,8 +776,8 @@ golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q= golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=

View File

@ -68,6 +68,25 @@ func MustRunCommand(cmd string, args ...string) {
MustRun(exec.Command(cmd, args...)) MustRun(exec.Command(cmd, args...))
} }
func MustRunCommandWithOutput(cmd string, args ...string) {
var done chan bool
// This is a little loop to generate some output, so CI does not tear down the
// process after 300 seconds.
go func() {
for i := 0; i < 15; i++ {
fmt.Printf("Waiting for command %q\n", cmd)
select {
case <-time.After(time.Minute):
break
case <-done:
return
}
}
}()
MustRun(exec.Command(cmd, args...))
close(done)
}
var warnedAboutGit bool var warnedAboutGit bool
// RunGit runs a git subcommand and returns its output. // RunGit runs a git subcommand and returns its output.

View File

@ -137,20 +137,35 @@ func (args *TransactionArgs) setFeeDefaults(ctx context.Context, b Backend) erro
if args.GasPrice != nil && (args.MaxFeePerGas != nil || args.MaxPriorityFeePerGas != nil) { if args.GasPrice != nil && (args.MaxFeePerGas != nil || args.MaxPriorityFeePerGas != nil) {
return errors.New("both gasPrice and (maxFeePerGas or maxPriorityFeePerGas) specified") return errors.New("both gasPrice and (maxFeePerGas or maxPriorityFeePerGas) specified")
} }
// If the tx has completely specified a fee mechanism, no default is needed. This allows users // If the tx has completely specified a fee mechanism, no default is needed.
// who are not yet synced past London to get defaults for other tx values. See // This allows users who are not yet synced past London to get defaults for
// https://github.com/ethereum/go-ethereum/pull/23274 for more information. // other tx values. See https://github.com/ethereum/go-ethereum/pull/23274
// for more information.
eip1559ParamsSet := args.MaxFeePerGas != nil && args.MaxPriorityFeePerGas != nil eip1559ParamsSet := args.MaxFeePerGas != nil && args.MaxPriorityFeePerGas != nil
if (args.GasPrice != nil && !eip1559ParamsSet) || (args.GasPrice == nil && eip1559ParamsSet) {
// Sanity check the EIP-1559 fee parameters if present. // Sanity check the EIP-1559 fee parameters if present.
if args.GasPrice == nil && args.MaxFeePerGas.ToInt().Cmp(args.MaxPriorityFeePerGas.ToInt()) < 0 { if args.GasPrice == nil && eip1559ParamsSet {
if args.MaxFeePerGas.ToInt().Sign() == 0 {
return errors.New("maxFeePerGas must be non-zero")
}
if args.MaxFeePerGas.ToInt().Cmp(args.MaxPriorityFeePerGas.ToInt()) < 0 {
return fmt.Errorf("maxFeePerGas (%v) < maxPriorityFeePerGas (%v)", args.MaxFeePerGas, args.MaxPriorityFeePerGas) return fmt.Errorf("maxFeePerGas (%v) < maxPriorityFeePerGas (%v)", args.MaxFeePerGas, args.MaxPriorityFeePerGas)
} }
return nil return nil // No need to set anything, user already set MaxFeePerGas and MaxPriorityFeePerGas
} }
// Now attempt to fill in default value depending on whether London is active or not. // Sanity check the non-EIP-1559 fee parameters.
head := b.CurrentHeader() head := b.CurrentHeader()
if b.ChainConfig().IsLondon(head.Number) { isLondon := b.ChainConfig().IsLondon(head.Number)
if args.GasPrice != nil && !eip1559ParamsSet {
// Zero gas-price is not allowed after London fork
if args.GasPrice.ToInt().Sign() == 0 && isLondon {
return errors.New("gasPrice must be non-zero after london fork")
}
return nil // No need to set anything, user already set GasPrice
}
// Now attempt to fill in default value depending on whether London is active or not.
if isLondon {
// London is active, set maxPriorityFeePerGas and maxFeePerGas. // London is active, set maxPriorityFeePerGas and maxFeePerGas.
if err := args.setLondonFeeDefaults(ctx, head, b); err != nil { if err := args.setLondonFeeDefaults(ctx, head, b); err != nil {
return err return err

View File

@ -52,6 +52,7 @@ func TestSetFeeDefaults(t *testing.T) {
var ( var (
b = newBackendMock() b = newBackendMock()
zero = (*hexutil.Big)(big.NewInt(0))
fortytwo = (*hexutil.Big)(big.NewInt(42)) fortytwo = (*hexutil.Big)(big.NewInt(42))
maxFee = (*hexutil.Big)(new(big.Int).Add(new(big.Int).Mul(b.current.BaseFee, big.NewInt(2)), fortytwo.ToInt())) maxFee = (*hexutil.Big)(new(big.Int).Add(new(big.Int).Mul(b.current.BaseFee, big.NewInt(2)), fortytwo.ToInt()))
al = &types.AccessList{types.AccessTuple{Address: common.Address{0xaa}, StorageKeys: []common.Hash{{0x01}}}} al = &types.AccessList{types.AccessTuple{Address: common.Address{0xaa}, StorageKeys: []common.Hash{{0x01}}}}
@ -66,6 +67,13 @@ func TestSetFeeDefaults(t *testing.T) {
&TransactionArgs{GasPrice: fortytwo}, &TransactionArgs{GasPrice: fortytwo},
nil, nil,
}, },
{
"legacy tx pre-London with zero price",
false,
&TransactionArgs{GasPrice: zero},
&TransactionArgs{GasPrice: zero},
nil,
},
{ {
"legacy tx post-London, explicit gas price", "legacy tx post-London, explicit gas price",
true, true,
@ -73,6 +81,13 @@ func TestSetFeeDefaults(t *testing.T) {
&TransactionArgs{GasPrice: fortytwo}, &TransactionArgs{GasPrice: fortytwo},
nil, nil,
}, },
{
"legacy tx post-London with zero price",
true,
&TransactionArgs{GasPrice: zero},
nil,
errors.New("gasPrice must be non-zero after london fork"),
},
// Access list txs // Access list txs
{ {
@ -161,6 +176,13 @@ func TestSetFeeDefaults(t *testing.T) {
nil, nil,
errors.New("maxFeePerGas (0x7) < maxPriorityFeePerGas (0x2a)"), errors.New("maxFeePerGas (0x7) < maxPriorityFeePerGas (0x2a)"),
}, },
{
"dynamic fee tx post-London, explicit gas price",
true,
&TransactionArgs{MaxFeePerGas: zero, MaxPriorityFeePerGas: zero},
nil,
errors.New("maxFeePerGas must be non-zero"),
},
// Misc // Misc
{ {

View File

@ -23,7 +23,7 @@ import (
const ( const (
VersionMajor = 1 // Major version component of the current release VersionMajor = 1 // Major version component of the current release
VersionMinor = 13 // Minor version component of the current release VersionMinor = 13 // Minor version component of the current release
VersionPatch = 6 // Patch version component of the current release VersionPatch = 7 // Patch version component of the current release
VersionMeta = "stable" // Version metadata to append to the version string VersionMeta = "stable" // Version metadata to append to the version string
) )