Skip to content

Commit

Permalink
Merge pull request #1211 from quorumbot/upgrade/go-ethereum/v1.9.21-2…
Browse files Browse the repository at this point in the history
…021609142421

[Upgrade] Go-Ethereum release v1.9.21
  • Loading branch information
ricardolyn committed Jun 15, 2021
2 parents c1d6176 + d574312 commit 94d12a9
Show file tree
Hide file tree
Showing 73 changed files with 1,108 additions and 8,225 deletions.
1 change: 0 additions & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,3 @@ p2p/simulations @fjl
p2p/protocols @fjl
p2p/testing @fjl
signer/ @holiman
whisper/ @gballet
148 changes: 75 additions & 73 deletions accounts/abi/bind/backends/simulated.go

Large diffs are not rendered by default.

67 changes: 55 additions & 12 deletions accounts/abi/bind/backends/simulated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ func TestNewSimulatedBackend(t *testing.T) {
t.Errorf("expected sim blockchain config to equal params.AllEthashProtocolChanges, got %v", sim.config)
}

statedb, _, _ := sim.blockchain.State()
bal := statedb.GetBalance(testAddr)
stateDB, _, _ := sim.blockchain.State()
bal := stateDB.GetBalance(testAddr)
if bal.Cmp(expectedBal) != 0 {
t.Errorf("expected balance for test address not received. expected: %v actual: %v", expectedBal, bal)
}
Expand All @@ -143,8 +143,7 @@ func TestSimulatedBackend_AdjustTime(t *testing.T) {
defer sim.Close()

prevTime := sim.pendingBlock.Time()
err := sim.AdjustTime(time.Second)
if err != nil {
if err := sim.AdjustTime(time.Second); err != nil {
t.Error(err)
}
newTime := sim.pendingBlock.Time()
Expand All @@ -154,6 +153,50 @@ func TestSimulatedBackend_AdjustTime(t *testing.T) {
}
}

func TestNewSimulatedBackend_AdjustTimeFail(t *testing.T) {
testAddr := crypto.PubkeyToAddress(testKey.PublicKey)
sim := simTestBackend(testAddr)
// Create tx and send
tx := types.NewTransaction(0, testAddr, big.NewInt(1000), params.TxGas, big.NewInt(1), nil)
signedTx, err := types.SignTx(tx, types.HomesteadSigner{}, testKey)
if err != nil {
t.Errorf("could not sign tx: %v", err)
}
err = sim.SendTransaction(context.Background(), signedTx, bind.PrivateTxArgs{})
if err != nil {
t.Error("Handled an error")
}
// AdjustTime should fail on non-empty block
if err := sim.AdjustTime(time.Second); err == nil {
t.Error("Expected adjust time to error on non-empty block")
}
sim.Commit()

prevTime := sim.pendingBlock.Time()
if err := sim.AdjustTime(time.Minute); err != nil {
t.Error(err)
}
newTime := sim.pendingBlock.Time()
if newTime-prevTime != uint64(time.Minute.Seconds()) {
t.Errorf("adjusted time not equal to a minute. prev: %v, new: %v", prevTime, newTime)
}
// Put a transaction after adjusting time
tx2 := types.NewTransaction(1, testAddr, big.NewInt(1000), params.TxGas, big.NewInt(1), nil)
signedTx2, err := types.SignTx(tx2, types.HomesteadSigner{}, testKey)
if err != nil {
t.Errorf("could not sign tx: %v", err)
}
err = sim.SendTransaction(context.Background(), signedTx2, bind.PrivateTxArgs{})
if err != nil {
t.Error("Handled an error")
}
sim.Commit()
newTime = sim.pendingBlock.Time()
if newTime-prevTime >= uint64(time.Minute.Seconds()) {
t.Errorf("time adjusted, but shouldn't be: prev: %v, new: %v", prevTime, newTime)
}
}

func TestSimulatedBackend_BalanceAt(t *testing.T) {
testAddr := crypto.PubkeyToAddress(testKey.PublicKey)
expectedBal := big.NewInt(10000000000)
Expand Down Expand Up @@ -484,7 +527,7 @@ func TestSimulatedBackend_EstimateGasWithPrice(t *testing.T) {
sim := NewSimulatedBackend(core.GenesisAlloc{addr: {Balance: big.NewInt(params.Ether*2 + 2e17)}}, 10000000)
defer sim.Close()

receipant := common.HexToAddress("deadbeef")
recipient := common.HexToAddress("deadbeef")
var cases = []struct {
name string
message ethereum.CallMsg
Expand All @@ -493,7 +536,7 @@ func TestSimulatedBackend_EstimateGasWithPrice(t *testing.T) {
}{
{"EstimateWithoutPrice", ethereum.CallMsg{
From: addr,
To: &receipant,
To: &recipient,
Gas: 0,
GasPrice: big.NewInt(0),
Value: big.NewInt(1000),
Expand All @@ -502,7 +545,7 @@ func TestSimulatedBackend_EstimateGasWithPrice(t *testing.T) {

{"EstimateWithPrice", ethereum.CallMsg{
From: addr,
To: &receipant,
To: &recipient,
Gas: 0,
GasPrice: big.NewInt(1000),
Value: big.NewInt(1000),
Expand All @@ -511,7 +554,7 @@ func TestSimulatedBackend_EstimateGasWithPrice(t *testing.T) {

{"EstimateWithVeryHighPrice", ethereum.CallMsg{
From: addr,
To: &receipant,
To: &recipient,
Gas: 0,
GasPrice: big.NewInt(1e14), // gascost = 2.1ether
Value: big.NewInt(1e17), // the remaining balance for fee is 2.1ether
Expand All @@ -520,7 +563,7 @@ func TestSimulatedBackend_EstimateGasWithPrice(t *testing.T) {

{"EstimateWithSuperhighPrice", ethereum.CallMsg{
From: addr,
To: &receipant,
To: &recipient,
Gas: 0,
GasPrice: big.NewInt(2e14), // gascost = 4.2ether
Value: big.NewInt(1000),
Expand Down Expand Up @@ -1049,12 +1092,12 @@ func TestSimulatedBackend_CallContractRevert(t *testing.T) {
t.Errorf("result from %v was not nil: %v", key, res)
}
if val != nil {
rerr, ok := err.(*revertError)
rErr, ok := err.(*revertError)
if !ok {
t.Errorf("expect revert error")
}
if rerr.Error() != "execution reverted: "+val.(string) {
t.Errorf("error was malformed: got %v want %v", rerr.Error(), val)
if rErr.Error() != "execution reverted: "+val.(string) {
t.Errorf("error was malformed: got %v want %v", rErr.Error(), val)
}
} else {
// revert(0x0,0x0)
Expand Down
2 changes: 1 addition & 1 deletion accounts/abi/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ func isDynamicType(t Type) bool {
func getTypeSize(t Type) int {
if t.T == ArrayTy && !isDynamicType(*t.Elem) {
// Recursively calculate type size if it is a nested array
if t.Elem.T == ArrayTy {
if t.Elem.T == ArrayTy || t.Elem.T == TupleTy {
return t.Size * getTypeSize(*t.Elem)
}
return t.Size * 32
Expand Down
36 changes: 36 additions & 0 deletions accounts/abi/type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,3 +330,39 @@ func TestInternalType(t *testing.T) {
t.Errorf("type %q: parsed type mismatch:\nGOT %s\nWANT %s ", blob, spew.Sdump(typeWithoutStringer(typ)), spew.Sdump(typeWithoutStringer(kind)))
}
}

func TestGetTypeSize(t *testing.T) {
var testCases = []struct {
typ string
components []ArgumentMarshaling
typSize int
}{
// simple array
{"uint256[2]", nil, 32 * 2},
{"address[3]", nil, 32 * 3},
{"bytes32[4]", nil, 32 * 4},
// array array
{"uint256[2][3][4]", nil, 32 * (2 * 3 * 4)},
// array tuple
{"tuple[2]", []ArgumentMarshaling{{Name: "x", Type: "bytes32"}, {Name: "y", Type: "bytes32"}}, (32 * 2) * 2},
// simple tuple
{"tuple", []ArgumentMarshaling{{Name: "x", Type: "uint256"}, {Name: "y", Type: "uint256"}}, 32 * 2},
// tuple array
{"tuple", []ArgumentMarshaling{{Name: "x", Type: "bytes32[2]"}}, 32 * 2},
// tuple tuple
{"tuple", []ArgumentMarshaling{{Name: "x", Type: "tuple", Components: []ArgumentMarshaling{{Name: "x", Type: "bytes32"}}}}, 32},
{"tuple", []ArgumentMarshaling{{Name: "x", Type: "tuple", Components: []ArgumentMarshaling{{Name: "x", Type: "bytes32[2]"}, {Name: "y", Type: "uint256"}}}}, 32 * (2 + 1)},
}

for i, data := range testCases {
typ, err := NewType(data.typ, "", data.components)
if err != nil {
t.Errorf("type %q: failed to parse type string: %v", data.typ, err)
}

result := getTypeSize(typ)
if result != data.typSize {
t.Errorf("case %d type %q: get type size error: actual: %d expected: %d", i, data.typ, result, data.typSize)
}
}
}
14 changes: 9 additions & 5 deletions accounts/usbwallet/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,18 +369,22 @@ func (w *wallet) selfDerive() {
w.log.Warn("USB wallet nonce retrieval failed", "err", err)
break
}
// If the next account is empty, stop self-derivation, but add for the last base path
// We've just self-derived a new account, start tracking it locally
// unless the account was empty.
path := make(accounts.DerivationPath, len(nextPaths[i]))
copy(path[:], nextPaths[i][:])
if balance.Sign() == 0 && nonce == 0 {
empty = true
// If it indeed was empty, make a log output for it anyway. In the case
// of legacy-ledger, the first account on the legacy-path will
// be shown to the user, even if we don't actively track it
if i < len(nextAddrs)-1 {
w.log.Info("Skipping trakcking first account on legacy path, use personal.deriveAccount(<url>,<path>, false) to track",
"path", path, "address", nextAddrs[i])
break
}
}
// We've just self-derived a new account, start tracking it locally
path := make(accounts.DerivationPath, len(nextPaths[i]))
copy(path[:], nextPaths[i][:])
paths = append(paths, path)

account := accounts.Account{
Address: nextAddrs[i],
URL: accounts.URL{Scheme: w.url.Scheme, Path: fmt.Sprintf("%s/%s", w.url.Path, path)},
Expand Down
5 changes: 0 additions & 5 deletions build/ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ var (
executablePath("geth"),
executablePath("puppeth"),
executablePath("rlpdump"),
executablePath("wnode"),
executablePath("clef"),
}

Expand Down Expand Up @@ -109,10 +108,6 @@ var (
BinaryName: "rlpdump",
Description: "Developer utility tool that prints RLP structures.",
},
{
BinaryName: "wnode",
Description: "Ethereum Whisper diagnostic tool",
},
{
BinaryName: "clef",
Description: "Ethereum account management tool.",
Expand Down
26 changes: 4 additions & 22 deletions cmd/geth/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import (
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/private"
"github.com/ethereum/go-ethereum/private/engine"
whisper "github.com/ethereum/go-ethereum/whisper/whisperv6"
"github.com/naoina/toml"
"gopkg.in/urfave/cli.v1"
)
Expand Down Expand Up @@ -79,7 +78,6 @@ type ethstatsConfig struct {

type gethConfig struct {
Eth eth.Config
Shh whisper.Config
Node node.Config
Ethstats ethstatsConfig
}
Expand Down Expand Up @@ -120,7 +118,6 @@ func makeConfigNode(ctx *cli.Context) (*node.Node, gethConfig) {
// Load defaults.
cfg := gethConfig{
Eth: eth.DefaultConfig,
Shh: whisper.DefaultConfig,
Node: defaultNodeConfig(),
}

Expand All @@ -141,19 +138,18 @@ func makeConfigNode(ctx *cli.Context) (*node.Node, gethConfig) {
if ctx.GlobalIsSet(utils.EthStatsURLFlag.Name) {
cfg.Ethstats.URL = ctx.GlobalString(utils.EthStatsURLFlag.Name)
}
utils.SetShhConfig(ctx, stack, &cfg.Shh)
utils.SetShhConfig(ctx, stack)

return stack, cfg
}

// enableWhisper returns true in case one of the whisper flags is set.
func enableWhisper(ctx *cli.Context) bool {
func checkWhisper(ctx *cli.Context) {
for _, flag := range whisperFlags {
if ctx.GlobalIsSet(flag.GetName()) {
return true
log.Warn("deprecated whisper flag detected. Whisper has been moved to github.com/ethereum/whisper")
}
}
return false
}

// makeFullNode loads geth configuration and creates the Ethereum backend.
Expand Down Expand Up @@ -183,21 +179,7 @@ func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) {
}
// End Quorum

// Whisper must be explicitly enabled by specifying at least 1 whisper flag or in dev mode
shhEnabled := enableWhisper(ctx)
shhAutoEnabled := !ctx.GlobalIsSet(utils.WhisperEnabledFlag.Name) && ctx.GlobalIsSet(utils.DeveloperFlag.Name)
if shhEnabled || shhAutoEnabled {
if ctx.GlobalIsSet(utils.WhisperMaxMessageSizeFlag.Name) {
cfg.Shh.MaxMessageSize = uint32(ctx.Int(utils.WhisperMaxMessageSizeFlag.Name))
}
if ctx.GlobalIsSet(utils.WhisperMinPOWFlag.Name) {
cfg.Shh.MinimumAcceptedPOW = ctx.Float64(utils.WhisperMinPOWFlag.Name)
}
if ctx.GlobalIsSet(utils.WhisperRestrictConnectionBetweenLightClientsFlag.Name) {
cfg.Shh.RestrictConnectionBetweenLightClients = true
}
utils.RegisterShhService(stack, &cfg.Shh)
}
checkWhisper(ctx)
// Configure GraphQL if requested
if ctx.GlobalIsSet(utils.GraphQLEnabledFlag.Name) {
utils.RegisterGraphQLService(stack, backend, cfg.Node)
Expand Down
9 changes: 3 additions & 6 deletions cmd/geth/consolecmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import (
)

const (
ipcAPIs = "admin:1.0 debug:1.0 eth:1.0 istanbul:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 shh:1.0 txpool:1.0 web3:1.0"
ipcAPIs = "admin:1.0 debug:1.0 eth:1.0 istanbul:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0"
httpAPIs = "admin:1.0 eth:1.0 net:1.0 rpc:1.0 web3:1.0"
nodeKey = "b68c0338aa4b266bf38ebe84c6199ae9fac8b29f32998b3ed2fbeafebe8d65c9"
)
Expand Down Expand Up @@ -84,7 +84,7 @@ func TestConsoleWelcome(t *testing.T) {
// Start a geth console, make sure it's cleaned up and terminate the console
geth := runGeth(t,
"--datadir", datadir, "--port", "0", "--maxpeers", "0", "--nodiscover", "--nat", "none",
"--etherbase", coinbase, "--shh",
"--etherbase", coinbase,
"console")

// Gather all the infos the welcome message needs to contain
Expand Down Expand Up @@ -128,12 +128,9 @@ func TestIPCAttachWelcome(t *testing.T) {
} else {
ipc = filepath.Join(datadir, "geth.ipc")
}

// Note: we need --shh because testAttachWelcome checks for default
// list of ipc modules and shh is included there.
geth := runGeth(t,
"--datadir", datadir, "--port", "0", "--maxpeers", "0", "--nodiscover", "--nat", "none",
"--etherbase", coinbase, "--shh", "--ipcpath", ipc)
"--etherbase", coinbase, "--ipcpath", ipc)

defer func() {
geth.Interrupt()
Expand Down
2 changes: 1 addition & 1 deletion cmd/geth/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ var AppHelpFlagGroups = []flags.FlagGroup{
Flags: metricsFlags,
},
{
Name: "WHISPER (EXPERIMENTAL)",
Name: "WHISPER (deprecated)",
Flags: whisperFlags,
},
{
Expand Down
Loading

0 comments on commit 94d12a9

Please sign in to comment.