Skip to content

Commit

Permalink
Merge pull request #268 from OffchainLabs/merge-v1.12.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Tristan-Wilson authored Nov 17, 2023
2 parents 6cacfc9 + c3635af commit 65bc346
Show file tree
Hide file tree
Showing 45 changed files with 194 additions and 151 deletions.
4 changes: 2 additions & 2 deletions accounts/keystore/account_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ import (
const minReloadInterval = 2 * time.Second

// byURL defines the sorting order for accounts.
func byURL(a, b accounts.Account) bool {
return a.URL.Cmp(b.URL) < 0
func byURL(a, b accounts.Account) int {
return a.URL.Cmp(b.URL)
}

// AmbiguousAddrError is returned when attempting to unlock
Expand Down
19 changes: 14 additions & 5 deletions build/ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,19 +200,24 @@ func doInstall(cmdline []string) {
staticlink = flag.Bool("static", false, "Create statically-linked executable")
)
flag.CommandLine.Parse(cmdline)
env := build.Env()

// Configure the toolchain.
tc := build.GoToolchain{GOARCH: *arch, CC: *cc}
if *dlgo {
csdb := build.MustLoadChecksums("build/checksums.txt")
tc.Root = build.DownloadGo(csdb, dlgoVersion)
}
// Disable CLI markdown doc generation in release builds and enable linking
// the CKZG library since we can make it portable here.
buildTags := []string{"urfave_cli_no_docs", "ckzg"}

// Disable CLI markdown doc generation in release builds.
buildTags := []string{"urfave_cli_no_docs"}

// Enable linking the CKZG library since we can make it work with additional flags.
if env.UbuntuVersion != "trusty" {
buildTags = append(buildTags, "ckzg")
}

// Configure the build.
env := build.Env()
gobuild := tc.Go("build", buildFlags(env, *staticlink, buildTags)...)

// arm64 CI builders are memory-constrained and can't handle concurrent builds,
Expand Down Expand Up @@ -298,10 +303,14 @@ func doTest(cmdline []string) {
csdb := build.MustLoadChecksums("build/checksums.txt")
tc.Root = build.DownloadGo(csdb, dlgoVersion)
}
gotest := tc.Go("test", "-tags=ckzg")
gotest := tc.Go("test")

// CI needs a bit more time for the statetests (default 10m).
gotest.Args = append(gotest.Args, "-timeout=20m")

// Enable CKZG backend in CI.
gotest.Args = append(gotest.Args, "-tags=ckzg")

// Test a single package at a time. CI builders are slow
// and some tests run into timeouts under load.
gotest.Args = append(gotest.Args, "-p", "1")
Expand Down
2 changes: 1 addition & 1 deletion build/deb/ethereum/deb.rules
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ override_dh_auto_build:
mv .mod $(GOPATH)/pkg/mod

# A fresh Go was built, all dependency downloads faked, hope build works now
../.go/bin/go run build/ci.go install -git-commit={{.Env.Commit}} -git-branch={{.Env.Branch}} -git-tag={{.Env.Tag}} -buildnum={{.Env.Buildnum}} -pull-request={{.Env.IsPullRequest}}
../.go/bin/go run build/ci.go install -git-commit={{.Env.Commit}} -git-branch={{.Env.Branch}} -git-tag={{.Env.Tag}} -buildnum={{.Env.Buildnum}} -pull-request={{.Env.IsPullRequest}} -ubuntu {{.Distro}}

override_dh_auto_test:

Expand Down
12 changes: 9 additions & 3 deletions cmd/devp2p/dns_route53.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,11 +288,17 @@ func makeDeletionChanges(records map[string]recordSet, keep map[string]string) [
// sortChanges ensures DNS changes are in leaf-added -> root-changed -> leaf-deleted order.
func sortChanges(changes []types.Change) {
score := map[string]int{"CREATE": 1, "UPSERT": 2, "DELETE": 3}
slices.SortFunc(changes, func(a, b types.Change) bool {
slices.SortFunc(changes, func(a, b types.Change) int {
if a.Action == b.Action {
return *a.ResourceRecordSet.Name < *b.ResourceRecordSet.Name
return strings.Compare(*a.ResourceRecordSet.Name, *b.ResourceRecordSet.Name)
}
return score[string(a.Action)] < score[string(b.Action)]
if score[string(a.Action)] < score[string(b.Action)] {
return -1
}
if score[string(a.Action)] > score[string(b.Action)] {
return 1
}
return 0
})
}

Expand Down
14 changes: 10 additions & 4 deletions cmd/devp2p/nodeset.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ func (ns nodeSet) nodes() []*enode.Node {
result = append(result, n.N)
}
// Sort by ID.
slices.SortFunc(result, func(a, b *enode.Node) bool {
return bytes.Compare(a.ID().Bytes(), b.ID().Bytes()) < 0
slices.SortFunc(result, func(a, b *enode.Node) int {
return bytes.Compare(a.ID().Bytes(), b.ID().Bytes())
})
return result
}
Expand All @@ -103,8 +103,14 @@ func (ns nodeSet) topN(n int) nodeSet {
for _, v := range ns {
byscore = append(byscore, v)
}
slices.SortFunc(byscore, func(a, b nodeJSON) bool {
return a.Score >= b.Score
slices.SortFunc(byscore, func(a, b nodeJSON) int {
if a.Score > b.Score {
return -1
}
if a.Score < b.Score {
return 1
}
return 0
})
result := make(nodeSet, n)
for _, v := range byscore[:n] {
Expand Down
12 changes: 6 additions & 6 deletions common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ func BigToHash(b *big.Int) Hash { return BytesToHash(b.Bytes()) }
// If b is larger than len(h), b will be cropped from the left.
func HexToHash(s string) Hash { return BytesToHash(FromHex(s)) }

// Less compares two hashes.
func (h Hash) Less(other Hash) bool {
return bytes.Compare(h[:], other[:]) < 0
// Cmp compares two hashes.
func (h Hash) Cmp(other Hash) int {
return bytes.Compare(h[:], other[:])
}

// Bytes gets the byte representation of the underlying hash.
Expand Down Expand Up @@ -231,9 +231,9 @@ func IsHexAddress(s string) bool {
return len(s) == 2*AddressLength && isHex(s)
}

// Less compares two addresses.
func (a Address) Less(other Address) bool {
return bytes.Compare(a[:], other[:]) < 0
// Cmp compares two addresses.
func (a Address) Cmp(other Address) int {
return bytes.Compare(a[:], other[:])
}

// Bytes gets the string representation of the underlying address.
Expand Down
2 changes: 1 addition & 1 deletion consensus/clique/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ func (s *Snapshot) signers() []common.Address {
for sig := range s.Signers {
sigs = append(sigs, sig)
}
slices.SortFunc(sigs, common.Address.Less)
slices.SortFunc(sigs, common.Address.Cmp)
return sigs
}

Expand Down
2 changes: 1 addition & 1 deletion consensus/clique/snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (ap *testerAccountPool) checkpoint(header *types.Header, signers []string)
for i, signer := range signers {
auths[i] = ap.address(signer)
}
slices.SortFunc(auths, common.Address.Less)
slices.SortFunc(auths, common.Address.Cmp)
for i, auth := range auths {
copy(header.Extra[extraVanity+i*common.AddressLength:], auth.Bytes())
}
Expand Down
4 changes: 2 additions & 2 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -1085,8 +1085,8 @@ func (bc *BlockChain) procFutureBlocks() {
}
}
if len(blocks) > 0 {
slices.SortFunc(blocks, func(a, b *types.Block) bool {
return a.NumberU64() < b.NumberU64()
slices.SortFunc(blocks, func(a, b *types.Block) int {
return a.Number().Cmp(b.Number())
})
// Insert one by one as chain insertion needs contiguous ancestry between blocks
for i := range blocks {
Expand Down
4 changes: 2 additions & 2 deletions core/rawdb/accessors_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -926,9 +926,9 @@ func WriteBadBlock(db ethdb.KeyValueStore, block *types.Block) {
Header: block.Header(),
Body: block.Body(),
})
slices.SortFunc(badBlocks, func(a, b *badBlock) bool {
slices.SortFunc(badBlocks, func(a, b *badBlock) int {
// Note: sorting in descending number order.
return a.Header.Number.Uint64() >= b.Header.Number.Uint64()
return -a.Header.Number.Cmp(b.Header.Number)
})
if len(badBlocks) > badBlockToKeep {
badBlocks = badBlocks[:badBlockToKeep]
Expand Down
8 changes: 3 additions & 5 deletions core/rawdb/chain_iterator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ package rawdb
import (
"math/big"
"reflect"
"sort"
"sync"
"testing"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"golang.org/x/exp/slices"
)

func TestChainIterator(t *testing.T) {
Expand Down Expand Up @@ -92,11 +92,9 @@ func TestChainIterator(t *testing.T) {
}
}
if !c.reverse {
slices.Sort(numbers)
sort.Ints(numbers)
} else {
slices.SortFunc(numbers, func(a, b int) bool {
return a > b // Sort descending
})
sort.Sort(sort.Reverse(sort.IntSlice(numbers)))
}
if !reflect.DeepEqual(numbers, c.expect) {
t.Fatalf("Case %d failed, visit element mismatch, want %v, got %v", i, c.expect, numbers)
Expand Down
4 changes: 2 additions & 2 deletions core/state/snapshot/difflayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ func (dl *diffLayer) AccountList() []common.Hash {
dl.accountList = append(dl.accountList, hash)
}
}
slices.SortFunc(dl.accountList, common.Hash.Less)
slices.SortFunc(dl.accountList, common.Hash.Cmp)
dl.memory += uint64(len(dl.accountList) * common.HashLength)
return dl.accountList
}
Expand Down Expand Up @@ -563,7 +563,7 @@ func (dl *diffLayer) StorageList(accountHash common.Hash) ([]common.Hash, bool)
for k := range storageMap {
storageList = append(storageList, k)
}
slices.SortFunc(storageList, common.Hash.Less)
slices.SortFunc(storageList, common.Hash.Cmp)
dl.storageList[accountHash] = storageList
dl.memory += uint64(len(dl.storageList)*common.HashLength + common.HashLength)
return storageList, destructed
Expand Down
18 changes: 11 additions & 7 deletions core/state/snapshot/iterator_fast.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,25 @@ type weightedIterator struct {
priority int
}

func (it *weightedIterator) Less(other *weightedIterator) bool {
func (it *weightedIterator) Cmp(other *weightedIterator) int {
// Order the iterators primarily by the account hashes
hashI := it.it.Hash()
hashJ := other.it.Hash()

switch bytes.Compare(hashI[:], hashJ[:]) {
case -1:
return true
return -1
case 1:
return false
return 1
}
// Same account/storage-slot in multiple layers, split by priority
return it.priority < other.priority
if it.priority < other.priority {
return -1
}
if it.priority > other.priority {
return 1
}
return 0
}

// fastIterator is a more optimized multi-layer iterator which maintains a
Expand Down Expand Up @@ -155,9 +161,7 @@ func (fi *fastIterator) init() {
}
}
// Re-sort the entire list
slices.SortFunc(fi.iterators, func(a, b *weightedIterator) bool {
return a.Less(b)
})
slices.SortFunc(fi.iterators, func(a, b *weightedIterator) int { return a.Cmp(b) })
fi.initiated = false
}

Expand Down
16 changes: 8 additions & 8 deletions core/txpool/blobpool/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ var (

// The below metrics track the per-shelf metrics for the primary blob store
// and the temporary limbo store.
shelfDatausedGaugeName = "blobpool/shelf-%d/dataused"
shelfDatagapsGaugeName = "blobpool/shelf-%d/datagaps"
shelfSlotusedGaugeName = "blobpool/shelf-%d/slotused"
shelfSlotgapsGaugeName = "blobpool/shelf-%d/slotgaps"
shelfDatausedGaugeName = "blobpool/shelf_%d/dataused"
shelfDatagapsGaugeName = "blobpool/shelf_%d/datagaps"
shelfSlotusedGaugeName = "blobpool/shelf_%d/slotused"
shelfSlotgapsGaugeName = "blobpool/shelf_%d/slotgaps"

limboShelfDatausedGaugeName = "blobpool/limbo/shelf-%d/dataused"
limboShelfDatagapsGaugeName = "blobpool/limbo/shelf-%d/datagaps"
limboShelfSlotusedGaugeName = "blobpool/limbo/shelf-%d/slotused"
limboShelfSlotgapsGaugeName = "blobpool/limbo/shelf-%d/slotgaps"
limboShelfDatausedGaugeName = "blobpool/limbo/shelf_%d/dataused"
limboShelfDatagapsGaugeName = "blobpool/limbo/shelf_%d/datagaps"
limboShelfSlotusedGaugeName = "blobpool/limbo/shelf_%d/slotused"
limboShelfSlotgapsGaugeName = "blobpool/limbo/shelf_%d/slotgaps"

// The oversized metrics aggregate the shelf stats above the max blob count
// limits to track transactions that are just huge, but don't contain blobs.
Expand Down
2 changes: 1 addition & 1 deletion eth/api_debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func TestAccountRange(t *testing.T) {
}
// Test to see if it's possible to recover from the middle of the previous
// set and get an even split between the first and second sets.
slices.SortFunc(hList, common.Hash.Less)
slices.SortFunc(hList, common.Hash.Cmp)
middleH := hList[AccountRangeMaxResults/2]
middleResult := accountRangeTest(t, &trie, sdb, middleH, AccountRangeMaxResults, AccountRangeMaxResults)
missing, infirst, insecond := 0, 0, 0
Expand Down
4 changes: 2 additions & 2 deletions eth/gasprice/feehistory.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ func (oracle *Oracle) processBlock(bf *blockFees, percentiles []float64) {
reward, _ := tx.EffectiveGasTip(bf.block.BaseFee())
sorter[i] = txGasAndReward{gasUsed: bf.receipts[i].GasUsed, reward: reward}
}
slices.SortStableFunc(sorter, func(a, b txGasAndReward) bool {
return a.reward.Cmp(b.reward) < 0
slices.SortStableFunc(sorter, func(a, b txGasAndReward) int {
return a.reward.Cmp(b.reward)
})

var txIndex int
Expand Down
6 changes: 3 additions & 3 deletions eth/gasprice/gasprice.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func (oracle *Oracle) SuggestTipCap(ctx context.Context) (*big.Int, error) {
}
price := lastPrice
if len(results) > 0 {
slices.SortFunc(results, func(a, b *big.Int) bool { return a.Cmp(b) < 0 })
slices.SortFunc(results, func(a, b *big.Int) int { return a.Cmp(b) })
price = results[(len(results)-1)*oracle.percentile/100]
}
if price.Cmp(oracle.maxPrice) > 0 {
Expand Down Expand Up @@ -247,12 +247,12 @@ func (oracle *Oracle) getBlockValues(ctx context.Context, blockNum uint64, limit
sortedTxs := make([]*types.Transaction, len(txs))
copy(sortedTxs, txs)
baseFee := block.BaseFee()
slices.SortFunc(sortedTxs, func(a, b *types.Transaction) bool {
slices.SortFunc(sortedTxs, func(a, b *types.Transaction) int {
// It's okay to discard the error because a tx would never be
// accepted into a block with an invalid effective tip.
tip1, _ := a.EffectiveGasTip(baseFee)
tip2, _ := b.EffectiveGasTip(baseFee)
return tip1.Cmp(tip2) < 0
return tip1.Cmp(tip2)
})

var prices []*big.Int
Expand Down
Loading

0 comments on commit 65bc346

Please sign in to comment.