Skip to content

Commit

Permalink
Merge pull request #2030 from niuxiaojie89/feature/bump-version-to-1.4.1
Browse files Browse the repository at this point in the history
merge 1.10.0
  • Loading branch information
benbaley authored Apr 19, 2023
2 parents db3055b + 723c8bf commit 39d245e
Show file tree
Hide file tree
Showing 20 changed files with 229 additions and 69 deletions.
3 changes: 3 additions & 0 deletions accounts/abi/abi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const jsondata = `
{ "type" : "function", "name" : "uint64[2]", "inputs" : [ { "name" : "inputs", "type" : "uint64[2]" } ] },
{ "type" : "function", "name" : "uint64[]", "inputs" : [ { "name" : "inputs", "type" : "uint64[]" } ] },
{ "type" : "function", "name" : "int8", "inputs" : [ { "name" : "inputs", "type" : "int8" } ] },
{ "type" : "function", "name" : "bytes32", "inputs" : [ { "name" : "inputs", "type" : "bytes32" } ] },
{ "type" : "function", "name" : "foo", "inputs" : [ { "name" : "inputs", "type" : "uint32" } ] },
{ "type" : "function", "name" : "bar", "inputs" : [ { "name" : "inputs", "type" : "uint32" }, { "name" : "string", "type" : "uint16" } ] },
{ "type" : "function", "name" : "slice", "inputs" : [ { "name" : "inputs", "type" : "uint32[2]" } ] },
Expand All @@ -68,6 +69,7 @@ var (
String, _ = NewType("string", "", nil)
Bool, _ = NewType("bool", "", nil)
Bytes, _ = NewType("bytes", "", nil)
Bytes32, _ = NewType("bytes32", "", nil)
Address, _ = NewType("address", "", nil)
Uint64Arr, _ = NewType("uint64[]", "", nil)
AddressArr, _ = NewType("address[]", "", nil)
Expand Down Expand Up @@ -98,6 +100,7 @@ var methods = map[string]Method{
"uint64[]": NewMethod("uint64[]", "uint64[]", Function, "", false, false, []Argument{{"inputs", Uint64Arr, false}}, nil),
"uint64[2]": NewMethod("uint64[2]", "uint64[2]", Function, "", false, false, []Argument{{"inputs", Uint64Arr2, false}}, nil),
"int8": NewMethod("int8", "int8", Function, "", false, false, []Argument{{"inputs", Int8, false}}, nil),
"bytes32": NewMethod("bytes32", "bytes32", Function, "", false, false, []Argument{{"inputs", Bytes32, false}}, nil),
"foo": NewMethod("foo", "foo", Function, "", false, false, []Argument{{"inputs", Uint32, false}}, nil),
"bar": NewMethod("bar", "bar", Function, "", false, false, []Argument{{"inputs", Uint32, false}, {"string", Uint16, false}}, nil),
"slice": NewMethod("slice", "slice", Function, "", false, false, []Argument{{"inputs", Uint32Arr2, false}}, nil),
Expand Down
64 changes: 64 additions & 0 deletions accounts/abi/bind/bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,70 @@ var bindTests = []struct {
nil,
nil,
},
// Tests that structs are correctly unpacked
{

`Structs`,
`
pragma solidity ^0.6.5;
pragma experimental ABIEncoderV2;
contract Structs {
struct A {
bytes32 B;
}
function F() public view returns (A[] memory a, uint256[] memory c, bool[] memory d) {
A[] memory a = new A[](2);
a[0].B = bytes32(uint256(1234) << 96);
uint256[] memory c;
bool[] memory d;
return (a, c, d);
}
function G() public view returns (A[] memory a) {
A[] memory a = new A[](2);
a[0].B = bytes32(uint256(1234) << 96);
return a;
}
}
`,
[]string{`608060405234801561001057600080fd5b50610278806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c806328811f591461003b5780636fecb6231461005b575b600080fd5b610043610070565b604051610052939291906101a0565b60405180910390f35b6100636100d6565b6040516100529190610186565b604080516002808252606082810190935282918291829190816020015b610095610131565b81526020019060019003908161008d575050805190915061026960611b9082906000906100be57fe5b60209081029190910101515293606093508392509050565b6040805160028082526060828101909352829190816020015b6100f7610131565b8152602001906001900390816100ef575050805190915061026960611b90829060009061012057fe5b602090810291909101015152905090565b60408051602081019091526000815290565b815260200190565b6000815180845260208085019450808401835b8381101561017b578151518752958201959082019060010161015e565b509495945050505050565b600060208252610199602083018461014b565b9392505050565b6000606082526101b3606083018661014b565b6020838203818501528186516101c98185610239565b91508288019350845b818110156101f3576101e5838651610143565b9484019492506001016101d2565b505084810360408601528551808252908201925081860190845b8181101561022b57825115158552938301939183019160010161020d565b509298975050505050505050565b9081526020019056fea2646970667358221220eb85327e285def14230424c52893aebecec1e387a50bb6b75fc4fdbed647f45f64736f6c63430006050033`},
[]string{`[{"inputs":[],"name":"F","outputs":[{"components":[{"internalType":"bytes32","name":"B","type":"bytes32"}],"internalType":"structStructs.A[]","name":"a","type":"tuple[]"},{"internalType":"uint256[]","name":"c","type":"uint256[]"},{"internalType":"bool[]","name":"d","type":"bool[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"G","outputs":[{"components":[{"internalType":"bytes32","name":"B","type":"bytes32"}],"internalType":"structStructs.A[]","name":"a","type":"tuple[]"}],"stateMutability":"view","type":"function"}]`},
`
"math/big"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/crypto"
`,
`
// Generate a new random account and a funded simulator
key, _ := crypto.GenerateKey()
auth, _ := bind.NewKeyedTransactorWithChainID(key, big.NewInt(1337))
sim := backends.NewSimulatedBackend(core.GenesisAlloc{auth.From: {Balance: big.NewInt(10000000000000000)}}, 10000000)
defer sim.Close()
// Deploy a structs method invoker contract and execute its default method
_, _, structs, err := DeployStructs(auth, sim)
if err != nil {
t.Fatalf("Failed to deploy defaulter contract: %v", err)
}
sim.Commit()
opts := bind.CallOpts{}
if _, err := structs.F(&opts); err != nil {
t.Fatalf("Failed to invoke F method: %v", err)
}
if _, err := structs.G(&opts); err != nil {
t.Fatalf("Failed to invoke G method: %v", err)
}
`,
nil,
nil,
nil,
nil,
},
// Tests that non-existent contracts are reported as such (though only simulator test)
{
`NonExistent`,
Expand Down
2 changes: 1 addition & 1 deletion accounts/abi/bind/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ var (
return *outstruct, err
}
{{range $i, $t := .Normalized.Outputs}}
outstruct.{{.Name}} = out[{{$i}}].({{bindtype .Type $structs}}){{end}}
outstruct.{{.Name}} = *abi.ConvertType(out[{{$i}}], new({{bindtype .Type $structs}})).(*{{bindtype .Type $structs}}){{end}}
return *outstruct, err
{{else}}
Expand Down
12 changes: 9 additions & 3 deletions accounts/keystore/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"path/filepath"
"time"

"github.com/pborman/uuid"
"github.com/google/uuid"

"github.com/PlatONnetwork/PlatON-Go/accounts"
"github.com/PlatONnetwork/PlatON-Go/common"
Expand Down Expand Up @@ -110,7 +110,10 @@ func (k *Key) UnmarshalJSON(j []byte) (err error) {
}

u := new(uuid.UUID)
*u = uuid.Parse(keyJSON.Id)
*u, err = uuid.Parse(keyJSON.Id)
if err != nil {
return err
}
k.Id = *u

addr, err := common.Bech32ToAddress(keyJSON.Address)
Expand All @@ -129,7 +132,10 @@ func (k *Key) UnmarshalJSON(j []byte) (err error) {
}

func newKeyFromECDSA(privateKeyECDSA *ecdsa.PrivateKey) *Key {
id := uuid.NewRandom()
id, err := uuid.NewRandom()
if err != nil {
panic(fmt.Sprintf("Could not create random uuid: %v", err))
}
key := &Key{
Id: id,
Address: crypto.PubkeyToAddress(privateKeyECDSA.PublicKey),
Expand Down
21 changes: 16 additions & 5 deletions accounts/keystore/passphrase.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import (
"github.com/PlatONnetwork/PlatON-Go/common"
"github.com/PlatONnetwork/PlatON-Go/common/math"
"github.com/PlatONnetwork/PlatON-Go/crypto"
"github.com/pborman/uuid"
"github.com/google/uuid"
"golang.org/x/crypto/pbkdf2"
"golang.org/x/crypto/scrypt"
)
Expand Down Expand Up @@ -221,9 +221,12 @@ func DecryptKey(keyjson []byte, auth string) (*Key, error) {
return nil, err
}
key := crypto.ToECDSAUnsafe(keyBytes)

id, err := uuid.FromBytes(keyId)
if err != nil {
return nil, err
}
return &Key{
Id: uuid.UUID(keyId),
Id: id,
Address: crypto.PubkeyToAddress(key.PublicKey),
PrivateKey: key,
}, nil
Expand All @@ -238,7 +241,11 @@ func decryptKeyV3(keyProtected *encryptedKeyJSONV3, auth string) (keyBytes []byt
return nil, nil, fmt.Errorf("cipher not supported: %v", keyProtected.Crypto.Cipher)
}

keyId = uuid.Parse(keyProtected.Id)
keyUUID, err := uuid.Parse(keyProtected.Id)
if err != nil {
return nil, nil, err
}
keyId = keyUUID[:]
mac, err := hex.DecodeString(keyProtected.Crypto.MAC)
if err != nil {
return nil, nil, err
Expand Down Expand Up @@ -272,7 +279,11 @@ func decryptKeyV3(keyProtected *encryptedKeyJSONV3, auth string) (keyBytes []byt
}

func decryptKeyV1(keyProtected *encryptedKeyJSONV1, auth string) (keyBytes []byte, keyId []byte, err error) {
keyId = uuid.Parse(keyProtected.Id)
keyUUID, err := uuid.Parse(keyProtected.Id)
if err != nil {
return nil, nil, err
}
keyId = keyUUID[:]
mac, err := hex.DecodeString(keyProtected.Crypto.MAC)
if err != nil {
return nil, nil, err
Expand Down
9 changes: 6 additions & 3 deletions accounts/keystore/presale.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"github.com/PlatONnetwork/PlatON-Go/accounts"
"github.com/PlatONnetwork/PlatON-Go/common"
"github.com/PlatONnetwork/PlatON-Go/crypto"
"github.com/pborman/uuid"
"github.com/google/uuid"
"golang.org/x/crypto/pbkdf2"
)

Expand All @@ -37,7 +37,10 @@ func importPreSaleKey(keyStore keyStore, keyJSON []byte, password string) (accou
if err != nil {
return accounts.Account{}, nil, err
}
key.Id = uuid.NewRandom()
key.Id, err = uuid.NewRandom()
if err != nil {
return accounts.Account{}, nil, err
}
a := accounts.Account{
Address: key.Address,
URL: accounts.URL{
Expand Down Expand Up @@ -86,7 +89,7 @@ func decryptPreSaleKey(fileContent []byte, password string) (key *Key, err error
ecKey := crypto.ToECDSAUnsafe(ethPriv)

key = &Key{
Id: nil,
Id: uuid.UUID{},
Address: crypto.PubkeyToAddress(ecKey.PublicKey),
PrivateKey: ecKey,
}
Expand Down
9 changes: 6 additions & 3 deletions cmd/keytool/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (

"github.com/PlatONnetwork/PlatON-Go/common"

"github.com/pborman/uuid"
"github.com/google/uuid"
"gopkg.in/urfave/cli.v1"

"github.com/PlatONnetwork/PlatON-Go/accounts/keystore"
Expand Down Expand Up @@ -95,9 +95,12 @@ If you want to encrypt an existing private key, it can be specified by setting
}

// Create the keyfile object with a random UUID.
id := uuid.NewRandom()
UUID, err := uuid.NewRandom()
if err != nil {
utils.Fatalf("Failed to generate random uuid: %v", err)
}
key := &keystore.Key{
Id: id,
Id: UUID,
Address: crypto.PubkeyToAddress(privateKey.PublicKey),
PrivateKey: privateKey,
}
Expand Down
15 changes: 4 additions & 11 deletions cmd/platon/consolecmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,13 @@ package main

import (
"fmt"
"os"
"os/signal"
"path/filepath"
"strings"
"syscall"

"github.com/PlatONnetwork/PlatON-Go/cmd/utils"
"github.com/PlatONnetwork/PlatON-Go/console"
"github.com/PlatONnetwork/PlatON-Go/node"
"github.com/PlatONnetwork/PlatON-Go/rpc"
"gopkg.in/urfave/cli.v1"
"path/filepath"
"strings"
)

var (
Expand Down Expand Up @@ -205,13 +201,10 @@ func ephemeralConsole(ctx *cli.Context) error {
utils.Fatalf("Failed to execute %s: %v", file, err)
}
}
// Wait for pending callbacks, but stop for Ctrl-C.
abort := make(chan os.Signal, 1)
signal.Notify(abort, syscall.SIGINT, syscall.SIGTERM)

go func() {
<-abort
os.Exit(0)
stack.Wait()
console.Stop(false)
}()
console.Stop(true)

Expand Down
12 changes: 6 additions & 6 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,9 @@ var (
Usage: "Time interval to regenerate the trie cache journal",
Value: ethconfig.Defaults.TrieCleanCacheRejournal,
}
SnapshotFlag = cli.BoolFlag{
SnapshotFlag = cli.BoolTFlag{
Name: "snapshot",
Usage: `Enables snapshot-database mode -- experimental work in progress feature`,
Usage: `Enables snapshot-database mode (default = enable)`,
}
CacheGCFlag = cli.IntFlag{
Name: "cache.gc",
Expand All @@ -313,9 +313,9 @@ var (
Usage: "Megabytes of memory allocated to triedb internal caching",
Value: ethconfig.Defaults.TrieDBCache,
}
CachePreimagesFlag = cli.BoolTFlag{
CachePreimagesFlag = cli.BoolFlag{
Name: "cache.preimages",
Usage: "Enable recording the SHA3/keccak preimages of trie keys (default: true)",
Usage: "Enable recording the SHA3/keccak preimages of trie keys",
}
MinerGasPriceFlag = BigFlag{
Name: "miner.gasprice",
Expand Down Expand Up @@ -1180,7 +1180,7 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
if ctx.GlobalIsSet(CacheFlag.Name) || ctx.GlobalIsSet(CacheSnapshotFlag.Name) {
cfg.SnapshotCache = ctx.GlobalInt(CacheFlag.Name) * ctx.GlobalInt(CacheSnapshotFlag.Name) / 100
}
if !ctx.GlobalIsSet(SnapshotFlag.Name) {
if !ctx.GlobalBool(SnapshotFlag.Name) {
// If snap-sync is requested, this flag is also required
if cfg.SyncMode == downloader.SnapSync {
log.Info("Snap sync requested, enabling --snapshot")
Expand Down Expand Up @@ -1436,7 +1436,7 @@ func MakeChain(ctx *cli.Context, stack *node.Node, readOnly bool) (chain *core.B
if ctx.GlobalIsSet(CacheFlag.Name) || ctx.GlobalIsSet(CacheTrieFlag.Name) {
cache.TrieCleanLimit = ctx.GlobalInt(CacheFlag.Name) * ctx.GlobalInt(CacheTrieFlag.Name) / 100
}
if !ctx.GlobalIsSet(SnapshotFlag.Name) {
if !ctx.GlobalBool(SnapshotFlag.Name) {
cache.SnapshotLimit = 0 // Disabled
}
if ethconfig.Defaults.DBDisabledGC && !cache.Preimages {
Expand Down
28 changes: 14 additions & 14 deletions core/rawdb/chain_iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,13 +245,13 @@ func indexTransactions(db ethdb.Database, from uint64, to uint64, interrupt chan
}
}
}
// If there exists uncommitted data, flush them.
if batch.ValueSize() > 0 {
WriteTxIndexTail(batch, lastNum) // Also write the tail there
if err := batch.Write(); err != nil {
log.Crit("Failed writing batch to db", "error", err)
return
}
// Flush the new indexing tail and the last committed data. It can also happen
// that the last batch is empty because nothing to index, but the tail has to
// be flushed anyway.
WriteTxIndexTail(batch, lastNum)
if err := batch.Write(); err != nil {
log.Crit("Failed writing batch to db", "error", err)
return
}
select {
case <-interrupt:
Expand Down Expand Up @@ -336,13 +336,13 @@ func unindexTransactions(db ethdb.Database, from uint64, to uint64, interrupt ch
}
}
}
// Commit the last batch if there exists uncommitted data
if batch.ValueSize() > 0 {
WriteTxIndexTail(batch, nextNum)
if err := batch.Write(); err != nil {
log.Crit("Failed writing batch to db", "error", err)
return
}
// Flush the new indexing tail and the last committed data. It can also happen
// that the last batch is empty because nothing to unindex, but the tail has to
// be flushed anyway.
WriteTxIndexTail(batch, nextNum)
if err := batch.Write(); err != nil {
log.Crit("Failed writing batch to db", "error", err)
return
}
select {
case <-interrupt:
Expand Down
3 changes: 1 addition & 2 deletions eth/downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,6 @@ func (d *Downloader) Synchronise(id string, head common.Hash, bn *big.Int, mode
case nil, errBusy, errCanceled:
return err
}

if errors.Is(err, errInvalidChain) || errors.Is(err, errBadPeer) || errors.Is(err, errTimeout) ||
errors.Is(err, errStallingPeer) || errors.Is(err, errEmptyHeaderSet) || errors.Is(err, errPeersUnavailable) ||
errors.Is(err, errTooOld) || errors.Is(err, errInvalidAncestor) {
Expand Down Expand Up @@ -1599,7 +1598,7 @@ func (d *Downloader) processFastSyncContent(latest *types.Header, pivot uint64)
}()

closeOnErr := func(s *stateSync) {
if err := s.Wait(); err != nil && err != errCancelStateFetch && err != errCanceled {
if err := s.Wait(); err != nil && err != errCancelStateFetch && err != errCanceled && err != snap.ErrCancelled {
d.queue.Close() // wake up Results
}
}
Expand Down
Loading

0 comments on commit 39d245e

Please sign in to comment.