Skip to content

Commit

Permalink
chore: update go-ethereum (#2342)
Browse files Browse the repository at this point in the history
  • Loading branch information
ralph-pichler committed Jul 27, 2021
1 parent c07b816 commit d27e04e
Show file tree
Hide file tree
Showing 11 changed files with 319 additions and 114 deletions.
11 changes: 4 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ go 1.15
require (
github.com/btcsuite/btcd v0.22.0-beta
github.com/coreos/go-semver v0.3.0
github.com/ethereum/go-ethereum v1.9.23
github.com/ethereum/go-ethereum v1.10.3
github.com/ethersphere/go-price-oracle-abi v0.1.0
github.com/ethersphere/go-storage-incentives-abi v0.3.0
github.com/ethersphere/go-sw3-abi v0.4.0
github.com/ethersphere/langos v1.0.0
github.com/gogo/protobuf v1.3.2
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-cmp v0.5.5
github.com/google/uuid v1.1.4 // indirect
github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00 // indirect
github.com/gorilla/handlers v1.4.2
github.com/gorilla/mux v1.7.4
Expand All @@ -25,7 +23,6 @@ require (
github.com/kardianos/service v1.2.0
github.com/klauspost/cpuid/v2 v2.0.8 // indirect
github.com/koron/go-ssdp v0.0.2 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/libp2p/go-libp2p v0.14.3
github.com/libp2p/go-libp2p-autonat v0.4.2
github.com/libp2p/go-libp2p-core v0.8.5
Expand Down Expand Up @@ -55,11 +52,11 @@ require (
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.7.0
github.com/syndtr/goleveldb v1.0.1-0.20200815110645-5c35d600f0ca
github.com/syndtr/goleveldb v1.0.1-0.20210305035536-64b5b1c73954
github.com/uber/jaeger-client-go v2.24.0+incompatible
github.com/uber/jaeger-lib v2.2.0+incompatible // indirect
github.com/vmihailenco/msgpack/v5 v5.3.4
github.com/wealdtech/go-ens/v3 v3.4.4
github.com/wealdtech/go-ens/v3 v3.4.6
gitlab.com/nolash/go-mockbytes v0.0.7
go.uber.org/atomic v1.8.0
go.uber.org/multierr v1.7.0 // indirect
Expand All @@ -69,7 +66,7 @@ require (
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf
golang.org/x/time v0.0.0-20191024005414-555d28b269f0
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324
google.golang.org/protobuf v1.27.1 // indirect
gopkg.in/ini.v1 v1.57.0 // indirect
gopkg.in/yaml.v2 v2.4.0
Expand Down
240 changes: 136 additions & 104 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pkg/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ func NewBee(addr string, publicKey *ecdsa.PublicKey, signer crypto.Signer, netwo

lightNodes := lightnode.NewContainer(swarmAddress)

senderMatcher := transaction.NewMatcher(swapBackend, types.NewEIP155Signer(big.NewInt(chainID)), stateStore)
senderMatcher := transaction.NewMatcher(swapBackend, types.NewEIP2930Signer(big.NewInt(chainID)), stateStore)

p2ps, err := libp2p.New(p2pCtx, signer, networkID, swarmAddress, addr, addressbook, stateStore, lightNodes, senderMatcher, logger, tracer, libp2p.Options{
PrivateKey: libp2pPrivateKey,
Expand Down
4 changes: 2 additions & 2 deletions pkg/settlement/swap/addressbook.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func peerKey(peer swarm.Address) string {

// chequebookPeerKey computes the key where to store the peer for a chequebook.
func chequebookPeerKey(chequebook common.Address) string {
return fmt.Sprintf("%s%s", peerChequebookPrefix, chequebook)
return fmt.Sprintf("%s%x", peerChequebookPrefix, chequebook)
}

// peerBeneficiaryKey computes the key where to store the beneficiary for a peer.
Expand All @@ -208,7 +208,7 @@ func peerBeneficiaryKey(peer swarm.Address) string {

// beneficiaryPeerKey computes the key where to store the peer for a beneficiary.
func beneficiaryPeerKey(peer common.Address) string {
return fmt.Sprintf("%s%s", beneficiaryPeerPrefix, peer)
return fmt.Sprintf("%s%x", beneficiaryPeerPrefix, peer)
}

func peerDeductedByKey(peer swarm.Address) string {
Expand Down
19 changes: 19 additions & 0 deletions pkg/settlement/swap/chequebook/chequebook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,3 +470,22 @@ func TestChequebookWithdrawInsufficientFunds(t *testing.T) {
t.Fatalf("got wrong error. wanted %v, got %v", chequebook.ErrInsufficientFunds, err)
}
}

func TestStateStoreKeys(t *testing.T) {
address := common.HexToAddress("0xabcd")

expected := "swap_cashout_000000000000000000000000000000000000abcd"
if chequebook.CashoutActionKey(address) != expected {
t.Fatalf("wrong cashout action key. wanted %s, got %s", expected, chequebook.CashoutActionKey(address))
}

expected = "swap_chequebook_last_issued_cheque_000000000000000000000000000000000000abcd"
if chequebook.LastIssuedChequeKey(address) != expected {
t.Fatalf("wrong last issued cheque key. wanted %s, got %s", expected, chequebook.LastIssuedChequeKey(address))
}

expected = "swap_chequebook_last_received_cheque__000000000000000000000000000000000000abcd"
if chequebook.LastReceivedChequeKey(address) != expected {
t.Fatalf("wrong last received cheque key. wanted %s, got %s", expected, chequebook.LastReceivedChequeKey(address))
}
}
7 changes: 7 additions & 0 deletions pkg/settlement/swap/chequebook/export_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package chequebook

var (
LastIssuedChequeKey = lastIssuedChequeKey
LastReceivedChequeKey = lastReceivedChequeKey
CashoutActionKey = cashoutActionKey
)
10 changes: 10 additions & 0 deletions pkg/settlement/swap/export_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package swap

var (
PeerKey = peerKey
ChequebookPeerKey = chequebookPeerKey
PeerBeneficiaryKey = peerBeneficiaryKey
BeneficiaryPeerKey = beneficiaryPeerKey
PeerDeductedByKey = peerDeductedByKey
PeerDeductedForKey = peerDeductedForKey
)
35 changes: 35 additions & 0 deletions pkg/settlement/swap/swap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -750,3 +750,38 @@ func TestCashoutStatus(t *testing.T) {
t.Fatalf("go wrong status. wanted %v, got %v", expectedStatus, returnedStatus)
}
}

func TestStateStoreKeys(t *testing.T) {
address := common.HexToAddress("0xabcd")
swarmAddress := swarm.MustParseHexAddress("deff")

expected := "swap_chequebook_peer_deff"
if swap.PeerKey(swarmAddress) != expected {
t.Fatalf("wrong peer key. wanted %s, got %s", expected, swap.PeerKey(swarmAddress))
}

expected = "swap_peer_chequebook_000000000000000000000000000000000000abcd"
if swap.ChequebookPeerKey(address) != expected {
t.Fatalf("wrong peer key. wanted %s, got %s", expected, swap.ChequebookPeerKey(address))
}

expected = "swap_peer_beneficiary_deff"
if swap.PeerBeneficiaryKey(swarmAddress) != expected {
t.Fatalf("wrong peer beneficiary key. wanted %s, got %s", expected, swap.PeerBeneficiaryKey(swarmAddress))
}

expected = "swap_beneficiary_peer_000000000000000000000000000000000000abcd"
if swap.BeneficiaryPeerKey(address) != expected {
t.Fatalf("wrong beneficiary peer key. wanted %s, got %s", expected, swap.BeneficiaryPeerKey(address))
}

expected = "swap_deducted_by_peer_deff"
if swap.PeerDeductedByKey(swarmAddress) != expected {
t.Fatalf("wrong peer deducted by key. wanted %s, got %s", expected, swap.PeerDeductedByKey(swarmAddress))
}

expected = "swap_deducted_for_peer_deff"
if swap.PeerDeductedForKey(swarmAddress) != expected {
t.Fatalf("wrong peer deducted for key. wanted %s, got %s", expected, swap.PeerDeductedForKey(swarmAddress))
}
}
43 changes: 43 additions & 0 deletions pkg/statestore/leveldb/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"errors"
"fmt"
"strings"

"github.com/ethereum/go-ethereum/common"
)

var (
Expand All @@ -35,6 +37,7 @@ const (
dbSchemaCleanInterval = "clean-interval"
dbSchemaNoStamp = "no-stamp"
dbSchemaFlushBlock = "flushblock"
dbSchemaSwapAddr = "swapaddr"
)

var (
Expand All @@ -54,6 +57,7 @@ var schemaMigrations = []migration{
{name: dbSchemaCleanInterval, fn: migrateGrace},
{name: dbSchemaNoStamp, fn: migrateStamp},
{name: dbSchemaFlushBlock, fn: migrateFB},
{name: dbSchemaSwapAddr, fn: migrateSwap},
}

func migrateFB(s *store) error {
Expand Down Expand Up @@ -108,6 +112,45 @@ func migrateGrace(s *store) error {
return nil
}

func migrateSwap(s *store) error {
migratePrefix := func(prefix string) error {
keys, err := collectKeys(s, prefix)
if err != nil {
return err
}

for _, key := range keys {
split := strings.SplitAfter(key, prefix)
if len(split) != 2 {
return errors.New("no peer in key")
}

addr := common.BytesToAddress([]byte(split[1]))
fixed := fmt.Sprintf("%s%x", prefix, addr)

var chequebookAddress common.Address
if err = s.Get(key, &chequebookAddress); err != nil {
return err
}

if err = s.Put(fixed, chequebookAddress); err != nil {
return err
}

if err = s.Delete(key); err != nil {
return err
}
}
return nil
}

if err := migratePrefix("swap_peer_chequebook_"); err != nil {
return err
}

return migratePrefix("swap_beneficiary_peer_")
}

func (s *store) migrate(schemaName string) error {
migrations, err := getMigrations(schemaName, dbSchemaCurrent, schemaMigrations, s)
if err != nil {
Expand Down
58 changes: 58 additions & 0 deletions pkg/statestore/leveldb/migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@ package leveldb

import (
"errors"
"fmt"
"io/ioutil"
"testing"

"github.com/ethereum/go-ethereum/common"
"github.com/ethersphere/bee/pkg/logging"
"github.com/ethersphere/bee/pkg/storage"
)

func TestOneMigration(t *testing.T) {
Expand Down Expand Up @@ -282,3 +285,58 @@ func TestMigrationErrorTo(t *testing.T) {
t.Errorf("migration ran but shouldnt have")
}
}

func TestMigrationSwap(t *testing.T) {
dir := t.TempDir()
logger := logging.New(ioutil.Discard, 0)

// start the fresh statestore with the sanctuary schema name
db, err := NewStateStore(dir, logger)
if err != nil {
t.Fatal(err)
}
defer db.Close()

address := common.HexToAddress("0xabcd")
storedAddress := common.HexToAddress("0xffff")

legacyKey1 := fmt.Sprintf("swap_peer_chequebook_%s", address[:])
legacyKey2 := fmt.Sprintf("swap_beneficiary_peer_%s", address[:])

if err = db.Put(legacyKey1, storedAddress); err != nil {
t.Fatal(err)
}

if err = db.Put(legacyKey2, storedAddress); err != nil {
t.Fatal(err)
}

if err = migrateSwap(db.(*store)); err != nil {
t.Fatal(err)
}

var retrievedAddress common.Address
if err = db.Get("swap_peer_chequebook_000000000000000000000000000000000000abcd", &retrievedAddress); err != nil {
t.Fatal(err)
}

if retrievedAddress != storedAddress {
t.Fatalf("got wrong address. wanted %x, got %x", storedAddress, retrievedAddress)
}

if err = db.Get("swap_beneficiary_peer_000000000000000000000000000000000000abcd", &retrievedAddress); err != nil {
t.Fatal(err)
}

if retrievedAddress != storedAddress {
t.Fatalf("got wrong address. wanted %x, got %x", storedAddress, retrievedAddress)
}

if err = db.Get(legacyKey1, &retrievedAddress); err != storage.ErrNotFound {
t.Fatalf("legacyKey1 not deleted. got error %v", err)
}

if err = db.Get(legacyKey2, &retrievedAddress); err != storage.ErrNotFound {
t.Fatalf("legacyKey2 not deleted. got error %v", err)
}
}
4 changes: 4 additions & 0 deletions pkg/transaction/sender_matcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,3 +237,7 @@ func (*mockSigner) Hash(tx *types.Transaction) common.Hash {
func (*mockSigner) Equal(types.Signer) bool {
return false
}

func (*mockSigner) ChainID() *big.Int {
return big.NewInt(0)
}

0 comments on commit d27e04e

Please sign in to comment.