Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update polkadot dependencies #417

Merged
merged 27 commits into from
Jun 28, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update receipts trie generation to work with GSRPC 1.10.3
  • Loading branch information
vgeddes committed Jun 22, 2021
commit 4f8ed74726228408c940100e29251b82170d8d88
17 changes: 1 addition & 16 deletions relayer/chain/ethereum/header_cache_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@
package ethereum

import (
"bytes"
"context"
"fmt"
"math"
"sync"

gethCommon "github.com/ethereum/go-ethereum/common"
gethTypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/rlp"
gethTrie "github.com/ethereum/go-ethereum/trie"
"github.com/snowfork/ethashproof"
"golang.org/x/sync/errgroup"
Expand Down Expand Up @@ -197,7 +195,7 @@ func (s *HeaderCacheState) GetReceiptTrie(ctx context.Context, hash gethCommon.H
if err != nil {
return nil, err
}
receiptTrie = s.makeTrie(receipts)
receiptTrie = MakeTrie(receipts)
if receiptTrie.Hash() != block.ReceiptHash() {
return nil, fmt.Errorf("Receipt trie does not match block receipt hash")
}
Expand Down Expand Up @@ -257,19 +255,6 @@ func (s *HeaderCacheState) GetEthashproofCache(number uint64) (*ethashproof.Data
return cacheState.currentCache, nil
}

func (s *HeaderCacheState) makeTrie(items gethTypes.Receipts) *gethTrie.Trie {
keyBuf := new(bytes.Buffer)
valueBuf := new(bytes.Buffer)
trie := new(gethTrie.Trie)
for i, item := range items {
keyBuf.Reset()
rlp.Encode(keyBuf, uint(i))
item.EncodeRLP(valueBuf)
trie.Update(keyBuf.Bytes(), valueBuf.Bytes())
}
return trie
}

func (s *HeaderCacheState) prepareNextEthashproofCache() error {
cacheState := s.ethashproofCacheState
cacheState.Mutex.Lock()
Expand Down
10 changes: 3 additions & 7 deletions relayer/chain/ethereum/message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,9 @@ func TestMessage_Proof(t *testing.T) {
}

// Construct Merkle Patricia Trie for receipts
keybuf := new(bytes.Buffer)
receiptTrie := new(gethTrie.Trie)
for i := 0; i < receipts.Len(); i++ {
keybuf.Reset()
rlp.Encode(keybuf, uint(i))
receiptTrie.Update(keybuf.Bytes(), receipts.GetRlp(i))
}
receiptTrie := ethereum.MakeTrie(receipts)
fmt.Println("Hash", receiptTrie.Hash())

if receiptTrie.Hash() != block.ReceiptHash() {
panic("Receipt trie does not match block receipt hash")
}
Expand Down
25 changes: 25 additions & 0 deletions relayer/chain/ethereum/trie.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package ethereum

import (
"bytes"

"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/trie"
)

func MakeTrie(items types.Receipts) *trie.Trie {
keyBuf := new(bytes.Buffer)
valueBuf := new(bytes.Buffer)
trie := new(trie.Trie)

for i := 0; i < items.Len(); i++ {
keyBuf.Reset()
valueBuf.Reset()

rlp.Encode(keyBuf, uint(i))
items.EncodeIndex(i, valueBuf)
trie.Update(keyBuf.Bytes(), valueBuf.Bytes())
}
return trie
}
17 changes: 1 addition & 16 deletions relayer/cmd/fetch_messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package cmd

import (
"bytes"
"context"
"encoding/hex"
"fmt"
Expand All @@ -18,7 +17,6 @@ import (
"github.com/ethereum/go-ethereum/common"
gethCommon "github.com/ethereum/go-ethereum/common"
gethTypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/rlp"
gethTrie "github.com/ethereum/go-ethereum/trie"
"github.com/snowfork/go-substrate-rpc-client/v3/types"
"github.com/snowfork/polkadot-ethereum/relayer/chain/ethereum"
Expand Down Expand Up @@ -113,7 +111,7 @@ func getEthContractEventsAndTrie(
if err != nil {
return nil, nil, err
}
trie := makeTrie(receipts)
trie := ethereum.MakeTrie(receipts)

allEvents := make([]*gethTypes.Log, 0)

Expand Down Expand Up @@ -241,16 +239,3 @@ func printEthContractEventForSub(mapping map[common.Address]string, event *gethT
fmt.Println("")
return nil
}

func makeTrie(items gethTypes.Receipts) *gethTrie.Trie {
keyBuf := new(bytes.Buffer)
valueBuf := new(bytes.Buffer)
trie := new(gethTrie.Trie)
for i, item := range items {
keyBuf.Reset()
rlp.Encode(keyBuf, uint(i))
item.EncodeRLP(valueBuf)
trie.Update(keyBuf.Bytes(), valueBuf.Bytes())
}
return trie
}
5 changes: 1 addition & 4 deletions relayer/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ require (
github.com/ChainSafe/go-schnorrkel v0.0.0-20210527232834-58622d036665 // indirect
github.com/VictoriaMetrics/fastcache v1.6.0 // indirect
github.com/allegro/bigcache v1.2.1 // indirect
github.com/btcsuite/btcd v0.22.0-beta // indirect
github.com/ethereum/go-ethereum v1.10.3
github.com/go-ole/go-ole v1.2.5 // indirect
github.com/holiman/uint256 v1.1.1 // indirect
github.com/influxdata/influxdb v1.8.3
github.com/jinzhu/gorm v1.9.16
github.com/jinzhu/now v1.1.2 // indirect
Expand All @@ -26,7 +24,7 @@ require (
github.com/rivo/uniseg v0.2.0 // indirect
github.com/sirupsen/logrus v1.7.0
github.com/snowfork/ethashproof v0.0.0-20210106050330-7fb8adbe0892
github.com/snowfork/go-substrate-rpc-client/v3 v3.0.0-20210617125713-6d4919bb7df7
github.com/snowfork/go-substrate-rpc-client/v3 v3.0.0-20210622111340-f741bfc1863b
github.com/spf13/afero v1.5.1 // indirect
github.com/spf13/cast v1.3.1 // indirect
github.com/spf13/cobra v1.1.1
Expand All @@ -36,7 +34,6 @@ require (
github.com/wealdtech/go-merkletree v1.0.0
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22 // indirect
golang.org/x/text v0.3.5 // indirect
google.golang.org/protobuf v1.25.0 // indirect
gopkg.in/ini.v1 v1.62.0 // indirect
Expand Down
7 changes: 2 additions & 5 deletions relayer/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ github.com/btcsuite/btcd v0.22.0-beta h1:LTDpDKUM5EeOFBPM8IXpinEcmZ6FWfNZbE3lfrf
github.com/btcsuite/btcd v0.22.0-beta/go.mod h1:9n5ntfhhHQBIhUvlhDvD3Qg6fRUj4jkN0VB8L8svzOA=
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA=
github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg=
github.com/btcsuite/btcutil v1.0.2/go.mod h1:j9HUFwoQRsZL3V4n+qG+CUnEGHOarIxfC3Le2Yhbcts=
github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce h1:YtWJF7RHm2pYCvA5t0RPmAaLUhREsKuKd+SLhxFbFeQ=
github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce/go.mod h1:0DVlHczLPewLcPGEIeUEzfOJhqGPQ0mJJRDBtD307+o=
github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd/go.mod h1:HHNXQzUsZCxOoE+CPiyCTO6x34Zs86zZUiwtpXoGdtg=
Expand Down Expand Up @@ -308,8 +307,6 @@ github.com/holiman/bloomfilter/v2 v2.0.3 h1:73e0e/V0tCydx14a0SCYS/EWCxgwLZ18CZcZ
github.com/holiman/bloomfilter/v2 v2.0.3/go.mod h1:zpoh+gs7qcpqrHr3dB55AMiJwo0iURXE7ZOP9L9hSkA=
github.com/holiman/uint256 v1.1.1 h1:4JywC80b+/hSfljFlEBLHrrh+CIONLDz9NuFl0af4Mw=
github.com/holiman/uint256 v1.1.1/go.mod h1:y4ga/t+u+Xwd7CpDgZESaRcWy0I7XMlTMA25ApIH5Jw=
github.com/holiman/uint256 v1.2.0 h1:gpSYcPLWGv4sG43I2mVLiDZCNDh/EpGjSk8tmtxitHM=
github.com/holiman/uint256 v1.2.0/go.mod h1:y4ga/t+u+Xwd7CpDgZESaRcWy0I7XMlTMA25ApIH5Jw=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/huin/goupnp v1.0.0/go.mod h1:n9v9KO1tAxYH82qOn+UTIFQDmx5n1Zxd/ClZDMX7Bnc=
github.com/huin/goupnp v1.0.1-0.20210310174557-0ca763054c88 h1:bcAj8KroPf552TScjFPIakjH2/tdIrIH8F+cc4v4SRo=
Expand Down Expand Up @@ -547,8 +544,8 @@ github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIK
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
github.com/snowfork/ethashproof v0.0.0-20210106050330-7fb8adbe0892 h1:gxkgKQvLyZ9P31+BOf0l+MHUNsmJjPe4LzCFfljWKWo=
github.com/snowfork/ethashproof v0.0.0-20210106050330-7fb8adbe0892/go.mod h1:Yy1jPDuUtVPG1b3XnRGiEHWPs09Yd5UphOTqPhN9XPU=
github.com/snowfork/go-substrate-rpc-client/v3 v3.0.0-20210617125713-6d4919bb7df7 h1:8dun4PENHSNYCAU4cgv3l2gftr8VmOVHkP6LugK/LH8=
github.com/snowfork/go-substrate-rpc-client/v3 v3.0.0-20210617125713-6d4919bb7df7/go.mod h1:0u5rh046Kd92a1KBPLEtQRzttSkUo8tqzM6+PqYV2Vc=
github.com/snowfork/go-substrate-rpc-client/v3 v3.0.0-20210622111340-f741bfc1863b h1:6GbNOJ+smNnWiDj39WSaoFsQJ30U6TjdYrkS9B5wsy0=
github.com/snowfork/go-substrate-rpc-client/v3 v3.0.0-20210622111340-f741bfc1863b/go.mod h1:n+dDFUtmhedjdLsXi8m+rWwwx1SEAEN1Uo2PFePK3bU=
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/spaolacci/murmur3 v1.0.1-0.20190317074736-539464a789e9/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
Expand Down