Skip to content

Commit

Permalink
Merge pull request #2261 from cheng762/feature/bump-version-to-1.5.1
Browse files Browse the repository at this point in the history
merge eth
  • Loading branch information
benbaley authored May 7, 2024
2 parents 6b5ae2d + 1cb635d commit 2afbce8
Show file tree
Hide file tree
Showing 89 changed files with 2,182 additions and 731 deletions.
22 changes: 11 additions & 11 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,6 @@ run:
# default is true. Enables skipping of directories:
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
skip-dirs-use-default: true
skip-files:
- core/genesis_alloc.go
- log/term/terminal_notwindows.go
- params/version_history.go
- accounts/usbwallet/trezor/trezor.go
- crypto/bls/mcl.go
skip-dirs:
- common/math
- common/json
- common/sort
- tests

linters:
disable-all: true
Expand Down Expand Up @@ -71,3 +60,14 @@ issues:
- 'SA1019: strings.Title is deprecated'
- 'SA1019: strings.Title has been deprecated since Go 1.18 and an alternative has been available since Go 1.0: The rule Title uses for word boundaries does not handle Unicode punctuation properly. Use golang.org/x/text/cases instead.'
- 'SA1029: should not use built-in type string as key for value'
exclude-files:
- core/genesis_alloc.go
- log/term/terminal_notwindows.go
- params/version_history.go
- accounts/usbwallet/trezor/trezor.go
- crypto/bls/mcl.go
exclude-dirs:
- common/math
- common/json
- common/sort
- tests
7 changes: 6 additions & 1 deletion accounts/abi/bind/backends/simulated.go
Original file line number Diff line number Diff line change
Expand Up @@ -769,8 +769,13 @@ func (b *SimulatedBackend) AdjustTime(adjustment time.Duration) error {
if len(b.pendingBlock.Transactions()) != 0 {
return errors.New("Could not adjust time on non-empty block")
}
// Get the last block
block := b.blockchain.GetBlockByHash(b.pendingBlock.ParentHash())
if block == nil {
return fmt.Errorf("could not find parent")
}

blocks, _ := core.GenerateChain(b.config, b.blockchain.CurrentBlock(), b.blockchain.Engine(), b.database, 1, func(number int, block *core.BlockGen) {
blocks, _ := core.GenerateChain(b.config, block, b.blockchain.Engine(), b.database, 1, func(number int, block *core.BlockGen) {
for _, tx := range b.pendingBlock.Transactions() {
block.AddTx(tx)
}
Expand Down
4 changes: 3 additions & 1 deletion accounts/abi/bind/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import (
"github.com/PlatONnetwork/PlatON-Go/event"
)

const basefeeWiggleMultiplier = 2

// SignerFn is a signer function callback when a contract requires a method to
// sign the transaction before submission.
type SignerFn func(common.Address, *types.Transaction) (*types.Transaction, error)
Expand Down Expand Up @@ -255,7 +257,7 @@ func (c *BoundContract) createDynamicTx(opts *TransactOpts, contract *common.Add
if gasFeeCap == nil {
gasFeeCap = new(big.Int).Add(
gasTipCap,
new(big.Int).Mul(head.BaseFee, big.NewInt(2)),
new(big.Int).Mul(head.BaseFee, big.NewInt(basefeeWiggleMultiplier)),
)
}
if gasFeeCap.Cmp(gasTipCap) < 0 {
Expand Down
2 changes: 1 addition & 1 deletion accounts/abi/unpack.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func forEachUnpack(t Type, output []byte, start, size int) (interface{}, error)
return nil, fmt.Errorf("cannot marshal input to array, size is negative (%d)", size)
}
if start+32*size > len(output) {
return nil, fmt.Errorf("abi: cannot marshal in to go array: offset %d would go over slice boundary (len=%d)", len(output), start+32*size)
return nil, fmt.Errorf("abi: cannot marshal into go array: offset %d would go over slice boundary (len=%d)", len(output), start+32*size)
}

// this value will become our slice or our array, depending on the type
Expand Down
38 changes: 27 additions & 11 deletions cmd/abigen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ package main
import (
"encoding/json"
"fmt"

"io"
"os"
"regexp"
"strings"

"github.com/urfave/cli/v2"

"github.com/PlatONnetwork/PlatON-Go/accounts/abi/bind"
"github.com/PlatONnetwork/PlatON-Go/cmd/utils"
"github.com/PlatONnetwork/PlatON-Go/common/compiler"
"github.com/PlatONnetwork/PlatON-Go/crypto"
"github.com/PlatONnetwork/PlatON-Go/internal/flags"
"github.com/PlatONnetwork/PlatON-Go/log"
"github.com/urfave/cli/v2"
)

var (
Expand Down Expand Up @@ -100,6 +100,7 @@ func init() {

func abigen(c *cli.Context) error {
utils.CheckExclusive(c, abiFlag, jsonFlag) // Only one source can be selected.

if c.String(pkgFlag.Name) == "" {
utils.Fatalf("No destination package specified (--pkg)")
}
Expand Down Expand Up @@ -159,16 +160,28 @@ func abigen(c *cli.Context) error {
types = append(types, kind)
} else {
// Generate the list of types to exclude from binding
exclude := make(map[string]bool)
for _, kind := range strings.Split(c.String(excFlag.Name), ",") {
exclude[strings.ToLower(kind)] = true
var exclude *nameFilter
if c.IsSet(excFlag.Name) {
var err error
if exclude, err = newNameFilter(strings.Split(c.String(excFlag.Name), ",")...); err != nil {
utils.Fatalf("Failed to parse excludes: %v", err)
}
}
var contracts map[string]*compiler.Contract

if c.IsSet(jsonFlag.Name) {
jsonOutput, err := os.ReadFile(c.String(jsonFlag.Name))
var (
input = c.String(jsonFlag.Name)
jsonOutput []byte
err error
)
if input == "-" {
jsonOutput, err = io.ReadAll(os.Stdin)
} else {
jsonOutput, err = os.ReadFile(input)
}
if err != nil {
utils.Fatalf("Failed to read combined-json from compiler: %v", err)
utils.Fatalf("Failed to read combined-json: %v", err)
}
contracts, err = compiler.ParseCombinedJSON(jsonOutput, "", "", "", "")
if err != nil {
Expand All @@ -177,7 +190,11 @@ func abigen(c *cli.Context) error {
}
// Gather all non-excluded contract for binding
for name, contract := range contracts {
if exclude[strings.ToLower(name)] {
// fully qualified name is of the form <solFilePath>:<type>
nameParts := strings.Split(name, ":")
typeName := nameParts[len(nameParts)-1]
if exclude != nil && exclude.Matches(name) {
fmt.Fprintf(os.Stderr, "excluding: %v\n", name)
continue
}
abi, err := json.Marshal(contract.Info.AbiDefinition) // Flatten the compiler parse
Expand All @@ -187,15 +204,14 @@ func abigen(c *cli.Context) error {
abis = append(abis, string(abi))
bins = append(bins, contract.Code)
sigs = append(sigs, contract.Hashes)
nameParts := strings.Split(name, ":")
types = append(types, nameParts[len(nameParts)-1])
types = append(types, typeName)

// Derive the library placeholder which is a 34 character prefix of the
// hex encoding of the keccak256 hash of the fully qualified library name.
// Note that the fully qualified library name is the path of its source
// file and the library name separated by ":".
libPattern := crypto.Keccak256Hash([]byte(name)).String()[2:36] // the first 2 chars are 0x
libs[libPattern] = nameParts[len(nameParts)-1]
libs[libPattern] = typeName
}
}
// Extract all aliases from the flags
Expand Down
58 changes: 58 additions & 0 deletions cmd/abigen/namefilter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package main

import (
"fmt"
"strings"
)

type nameFilter struct {
fulls map[string]bool // path/to/contract.sol:Type
files map[string]bool // path/to/contract.sol:*
types map[string]bool // *:Type
}

func newNameFilter(patterns ...string) (*nameFilter, error) {
f := &nameFilter{
fulls: make(map[string]bool),
files: make(map[string]bool),
types: make(map[string]bool),
}
for _, pattern := range patterns {
if err := f.add(pattern); err != nil {
return nil, err
}
}
return f, nil
}

func (f *nameFilter) add(pattern string) error {
ft := strings.Split(pattern, ":")
if len(ft) != 2 {
// filenames and types must not include ':' symbol
return fmt.Errorf("invalid pattern: %s", pattern)
}

file, typ := ft[0], ft[1]
if file == "*" {
f.types[typ] = true
return nil
} else if typ == "*" {
f.files[file] = true
return nil
}
f.fulls[pattern] = true
return nil
}

func (f *nameFilter) Matches(name string) bool {
ft := strings.Split(name, ":")
if len(ft) != 2 {
// If contract names are always of the fully-qualified form
// <filePath>:<type>, then this case will never happen.
return false
}

file, typ := ft[0], ft[1]
// full paths > file paths > types
return f.fulls[name] || f.files[file] || f.types[typ]
}
38 changes: 38 additions & 0 deletions cmd/abigen/namefilter_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package main

import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestNameFilter(t *testing.T) {
_, err := newNameFilter("Foo")
require.Error(t, err)
_, err = newNameFilter("too/many:colons:Foo")
require.Error(t, err)

f, err := newNameFilter("a/path:A", "*:B", "c/path:*")
require.NoError(t, err)

for _, tt := range []struct {
name string
match bool
}{
{"a/path:A", true},
{"unknown/path:A", false},
{"a/path:X", false},
{"unknown/path:X", false},
{"any/path:B", true},
{"c/path:X", true},
{"c/path:foo:B", false},
} {
match := f.Matches(tt.name)
if tt.match {
assert.True(t, match, "expected match")
} else {
assert.False(t, match, "expected no match")
}
}
}
11 changes: 6 additions & 5 deletions cmd/platon/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ import (
"encoding/json"
"errors"
"fmt"

"os"
"reflect"
"unicode"

"github.com/naoina/toml"
cli "github.com/urfave/cli/v2"

"github.com/PlatONnetwork/PlatON-Go/accounts/external"
"github.com/PlatONnetwork/PlatON-Go/accounts/keystore"
"github.com/PlatONnetwork/PlatON-Go/cmd/utils"
Expand All @@ -38,8 +40,6 @@ import (
"github.com/PlatONnetwork/PlatON-Go/metrics"
"github.com/PlatONnetwork/PlatON-Go/node"
"github.com/PlatONnetwork/PlatON-Go/params"
"github.com/naoina/toml"
cli "github.com/urfave/cli/v2"
)

var (
Expand Down Expand Up @@ -200,12 +200,13 @@ func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) {
if cfg.Eth.NetworkId == 1 && ghash == params.MainnetGenesisHash {
firstIdx = 1
}
isLegacy, _, err := dbHasLegacyReceipts(eth.ChainDb(), firstIdx)
isLegacy, firstLegacy, err := dbHasLegacyReceipts(eth.ChainDb(), firstIdx)
if err != nil {
log.Error("Failed to check db for legacy receipts", "err", err)
} else if isLegacy {
stack.Close()
utils.Fatalf("Database has receipts with a legacy format. Please run `geth db freezer-migrate`.")
log.Error("Database has receipts with a legacy format", "firstLegacy", firstLegacy)
utils.Fatalf("Aborting. Please run `platon db freezer-migrate`.")
}
}

Expand Down
11 changes: 8 additions & 3 deletions cmd/platon/dbcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ import (
"syscall"
"time"

"github.com/olekukonko/tablewriter"
"github.com/urfave/cli/v2"

"github.com/PlatONnetwork/PlatON-Go/cmd/utils"
"github.com/PlatONnetwork/PlatON-Go/common"
"github.com/PlatONnetwork/PlatON-Go/common/hexutil"
Expand All @@ -39,8 +42,6 @@ import (
"github.com/PlatONnetwork/PlatON-Go/internal/flags"
"github.com/PlatONnetwork/PlatON-Go/log"
"github.com/PlatONnetwork/PlatON-Go/trie"
"github.com/olekukonko/tablewriter"
"github.com/urfave/cli/v2"
)

var (
Expand Down Expand Up @@ -820,11 +821,15 @@ func dbHasLegacyReceipts(db ethdb.Database, firstIdx uint64) (bool, uint64, erro
}
}
}
// Is first non-empty receipt legacy?
first, err := db.Ancient("receipts", firstIdx)
if err != nil {
return false, 0, err
}
// We looped over all receipts and they were all empty
if bytes.Equal(first, emptyRLPList) {
return false, 0, nil
}
// Is first non-empty receipt legacy?
legacy, err = types.IsLegacyStoredReceipts(first)
return legacy, firstIdx, err
}
Loading

0 comments on commit 2afbce8

Please sign in to comment.