From 6e8069a6662cab107d87c36b702afde2f656b713 Mon Sep 17 00:00:00 2001 From: ron Date: Fri, 24 Feb 2023 09:40:13 +0800 Subject: [PATCH] More cleanup --- relayer/contracts/basic/inbound.go | 201 +++++++++++++++++++++- relayer/contracts/generate.go | 8 +- relayer/go.mod | 2 +- relayer/go.sum | 2 + relayer/relays/beefy/ethereum-writer.go | 4 +- relayer/relays/beefy/polkadot-listener.go | 2 +- relayer/relays/parachain/logger.go | 2 +- relayer/relays/parachain/types.go | 2 +- 8 files changed, 211 insertions(+), 12 deletions(-) diff --git a/relayer/contracts/basic/inbound.go b/relayer/contracts/basic/inbound.go index 3b644e349d..b71e90ac53 100644 --- a/relayer/contracts/basic/inbound.go +++ b/relayer/contracts/basic/inbound.go @@ -30,14 +30,14 @@ var ( // BasicInboundChannelMessage is an auto generated low-level Go binding around an user-defined struct. type BasicInboundChannelMessage struct { - SourceId [32]byte + SourceID [32]byte Nonce uint64 Payload []byte } // BasicInboundChannelMetaData contains all meta data concerning the BasicInboundChannel contract. var BasicInboundChannelMetaData = &bind.MetaData{ - ABI: "[{\"inputs\":[{\"internalType\":\"contractParachainClient\",\"name\":\"_parachainClient\",\"type\":\"address\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"name\":\"nonce\",\"outputs\":[{\"internalType\":\"uint64\",\"name\":\"\",\"type\":\"uint64\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"parachainClient\",\"outputs\":[{\"internalType\":\"contractParachainClient\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"components\":[{\"internalType\":\"bytes32\",\"name\":\"sourceId\",\"type\":\"bytes32\"},{\"internalType\":\"uint64\",\"name\":\"nonce\",\"type\":\"uint64\"},{\"internalType\":\"bytes\",\"name\":\"payload\",\"type\":\"bytes\"}],\"internalType\":\"structBasicInboundChannel.Message\",\"name\":\"message\",\"type\":\"tuple\"},{\"internalType\":\"bytes32[]\",\"name\":\"leafProof\",\"type\":\"bytes32[]\"},{\"internalType\":\"bool[]\",\"name\":\"hashSides\",\"type\":\"bool[]\"},{\"internalType\":\"bytes\",\"name\":\"parachainHeaderProof\",\"type\":\"bytes\"}],\"name\":\"submit\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]", + ABI: "[{\"inputs\":[{\"internalType\":\"contractParachainClient\",\"name\":\"_parachainClient\",\"type\":\"address\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"sourceID\",\"type\":\"bytes32\"},{\"indexed\":false,\"internalType\":\"uint64\",\"name\":\"nonce\",\"type\":\"uint64\"}],\"name\":\"MessageDispatched\",\"type\":\"event\"},{\"inputs\":[],\"name\":\"GAS_BUFFER\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"MAX_GAS_PER_MESSAGE\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"name\":\"nonce\",\"outputs\":[{\"internalType\":\"uint64\",\"name\":\"\",\"type\":\"uint64\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"parachainClient\",\"outputs\":[{\"internalType\":\"contractParachainClient\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"components\":[{\"internalType\":\"bytes32\",\"name\":\"sourceID\",\"type\":\"bytes32\"},{\"internalType\":\"uint64\",\"name\":\"nonce\",\"type\":\"uint64\"},{\"internalType\":\"bytes\",\"name\":\"payload\",\"type\":\"bytes\"}],\"internalType\":\"structBasicInboundChannel.Message\",\"name\":\"message\",\"type\":\"tuple\"},{\"internalType\":\"bytes32[]\",\"name\":\"leafProof\",\"type\":\"bytes32[]\"},{\"internalType\":\"bool[]\",\"name\":\"hashSides\",\"type\":\"bool[]\"},{\"internalType\":\"bytes\",\"name\":\"parachainHeaderProof\",\"type\":\"bytes\"}],\"name\":\"submit\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]", } // BasicInboundChannelABI is the input ABI used to generate the binding from. @@ -186,6 +186,68 @@ func (_BasicInboundChannel *BasicInboundChannelTransactorRaw) Transact(opts *bin return _BasicInboundChannel.Contract.contract.Transact(opts, method, params...) } +// GASBUFFER is a free data retrieval call binding the contract method 0xc7e67360. +// +// Solidity: function GAS_BUFFER() view returns(uint256) +func (_BasicInboundChannel *BasicInboundChannelCaller) GASBUFFER(opts *bind.CallOpts) (*big.Int, error) { + var out []interface{} + err := _BasicInboundChannel.contract.Call(opts, &out, "GAS_BUFFER") + + if err != nil { + return *new(*big.Int), err + } + + out0 := *abi.ConvertType(out[0], new(*big.Int)).(**big.Int) + + return out0, err + +} + +// GASBUFFER is a free data retrieval call binding the contract method 0xc7e67360. +// +// Solidity: function GAS_BUFFER() view returns(uint256) +func (_BasicInboundChannel *BasicInboundChannelSession) GASBUFFER() (*big.Int, error) { + return _BasicInboundChannel.Contract.GASBUFFER(&_BasicInboundChannel.CallOpts) +} + +// GASBUFFER is a free data retrieval call binding the contract method 0xc7e67360. +// +// Solidity: function GAS_BUFFER() view returns(uint256) +func (_BasicInboundChannel *BasicInboundChannelCallerSession) GASBUFFER() (*big.Int, error) { + return _BasicInboundChannel.Contract.GASBUFFER(&_BasicInboundChannel.CallOpts) +} + +// MAXGASPERMESSAGE is a free data retrieval call binding the contract method 0x49bee574. +// +// Solidity: function MAX_GAS_PER_MESSAGE() view returns(uint256) +func (_BasicInboundChannel *BasicInboundChannelCaller) MAXGASPERMESSAGE(opts *bind.CallOpts) (*big.Int, error) { + var out []interface{} + err := _BasicInboundChannel.contract.Call(opts, &out, "MAX_GAS_PER_MESSAGE") + + if err != nil { + return *new(*big.Int), err + } + + out0 := *abi.ConvertType(out[0], new(*big.Int)).(**big.Int) + + return out0, err + +} + +// MAXGASPERMESSAGE is a free data retrieval call binding the contract method 0x49bee574. +// +// Solidity: function MAX_GAS_PER_MESSAGE() view returns(uint256) +func (_BasicInboundChannel *BasicInboundChannelSession) MAXGASPERMESSAGE() (*big.Int, error) { + return _BasicInboundChannel.Contract.MAXGASPERMESSAGE(&_BasicInboundChannel.CallOpts) +} + +// MAXGASPERMESSAGE is a free data retrieval call binding the contract method 0x49bee574. +// +// Solidity: function MAX_GAS_PER_MESSAGE() view returns(uint256) +func (_BasicInboundChannel *BasicInboundChannelCallerSession) MAXGASPERMESSAGE() (*big.Int, error) { + return _BasicInboundChannel.Contract.MAXGASPERMESSAGE(&_BasicInboundChannel.CallOpts) +} + // Nonce is a free data retrieval call binding the contract method 0x905da30f. // // Solidity: function nonce(bytes32 ) view returns(uint64) @@ -268,3 +330,138 @@ func (_BasicInboundChannel *BasicInboundChannelSession) Submit(message BasicInbo func (_BasicInboundChannel *BasicInboundChannelTransactorSession) Submit(message BasicInboundChannelMessage, leafProof [][32]byte, hashSides []bool, parachainHeaderProof []byte) (*types.Transaction, error) { return _BasicInboundChannel.Contract.Submit(&_BasicInboundChannel.TransactOpts, message, leafProof, hashSides, parachainHeaderProof) } + +// BasicInboundChannelMessageDispatchedIterator is returned from FilterMessageDispatched and is used to iterate over the raw logs and unpacked data for MessageDispatched events raised by the BasicInboundChannel contract. +type BasicInboundChannelMessageDispatchedIterator struct { + Event *BasicInboundChannelMessageDispatched // Event containing the contract specifics and raw log + + contract *bind.BoundContract // Generic contract to use for unpacking event data + event string // Event name to use for unpacking event data + + logs chan types.Log // Log channel receiving the found contract events + sub ethereum.Subscription // Subscription for errors, completion and termination + done bool // Whether the subscription completed delivering logs + fail error // Occurred error to stop iteration +} + +// Next advances the iterator to the subsequent event, returning whether there +// are any more events found. In case of a retrieval or parsing error, false is +// returned and Error() can be queried for the exact failure. +func (it *BasicInboundChannelMessageDispatchedIterator) Next() bool { + // If the iterator failed, stop iterating + if it.fail != nil { + return false + } + // If the iterator completed, deliver directly whatever's available + if it.done { + select { + case log := <-it.logs: + it.Event = new(BasicInboundChannelMessageDispatched) + if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { + it.fail = err + return false + } + it.Event.Raw = log + return true + + default: + return false + } + } + // Iterator still in progress, wait for either a data or an error event + select { + case log := <-it.logs: + it.Event = new(BasicInboundChannelMessageDispatched) + if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { + it.fail = err + return false + } + it.Event.Raw = log + return true + + case err := <-it.sub.Err(): + it.done = true + it.fail = err + return it.Next() + } +} + +// Error returns any retrieval or parsing error occurred during filtering. +func (it *BasicInboundChannelMessageDispatchedIterator) Error() error { + return it.fail +} + +// Close terminates the iteration process, releasing any pending underlying +// resources. +func (it *BasicInboundChannelMessageDispatchedIterator) Close() error { + it.sub.Unsubscribe() + return nil +} + +// BasicInboundChannelMessageDispatched represents a MessageDispatched event raised by the BasicInboundChannel contract. +type BasicInboundChannelMessageDispatched struct { + SourceID [32]byte + Nonce uint64 + Raw types.Log // Blockchain specific contextual infos +} + +// FilterMessageDispatched is a free log retrieval operation binding the contract event 0xc799cfcb5e2e85a0259b8a763245692fb69e6b3dd5319566347caf981b204e1c. +// +// Solidity: event MessageDispatched(bytes32 sourceID, uint64 nonce) +func (_BasicInboundChannel *BasicInboundChannelFilterer) FilterMessageDispatched(opts *bind.FilterOpts) (*BasicInboundChannelMessageDispatchedIterator, error) { + + logs, sub, err := _BasicInboundChannel.contract.FilterLogs(opts, "MessageDispatched") + if err != nil { + return nil, err + } + return &BasicInboundChannelMessageDispatchedIterator{contract: _BasicInboundChannel.contract, event: "MessageDispatched", logs: logs, sub: sub}, nil +} + +// WatchMessageDispatched is a free log subscription operation binding the contract event 0xc799cfcb5e2e85a0259b8a763245692fb69e6b3dd5319566347caf981b204e1c. +// +// Solidity: event MessageDispatched(bytes32 sourceID, uint64 nonce) +func (_BasicInboundChannel *BasicInboundChannelFilterer) WatchMessageDispatched(opts *bind.WatchOpts, sink chan<- *BasicInboundChannelMessageDispatched) (event.Subscription, error) { + + logs, sub, err := _BasicInboundChannel.contract.WatchLogs(opts, "MessageDispatched") + if err != nil { + return nil, err + } + return event.NewSubscription(func(quit <-chan struct{}) error { + defer sub.Unsubscribe() + for { + select { + case log := <-logs: + // New log arrived, parse the event and forward to the user + event := new(BasicInboundChannelMessageDispatched) + if err := _BasicInboundChannel.contract.UnpackLog(event, "MessageDispatched", log); err != nil { + return err + } + event.Raw = log + + select { + case sink <- event: + case err := <-sub.Err(): + return err + case <-quit: + return nil + } + case err := <-sub.Err(): + return err + case <-quit: + return nil + } + } + }), nil +} + +// ParseMessageDispatched is a log parse operation binding the contract event 0xc799cfcb5e2e85a0259b8a763245692fb69e6b3dd5319566347caf981b204e1c. +// +// Solidity: event MessageDispatched(bytes32 sourceID, uint64 nonce) +func (_BasicInboundChannel *BasicInboundChannelFilterer) ParseMessageDispatched(log types.Log) (*BasicInboundChannelMessageDispatched, error) { + event := new(BasicInboundChannelMessageDispatched) + if err := _BasicInboundChannel.contract.UnpackLog(event, "MessageDispatched", log); err != nil { + return nil, err + } + event.Raw = log + return event, nil +} diff --git a/relayer/contracts/generate.go b/relayer/contracts/generate.go index de7b96a857..77e4848326 100644 --- a/relayer/contracts/generate.go +++ b/relayer/contracts/generate.go @@ -1,6 +1,6 @@ -//go:generate bash -c "jq .abi ../../core/packages/contracts/artifacts/contracts/utils/OpaqueProof.sol/OpaqueProof.json | abigen --abi - --type OpaqueProof --pkg opaqueproof --out opaqueproof/contract.go" -//go:generate bash -c "jq .abi ../../core/packages/contracts/artifacts/contracts/BeefyClient.sol/BeefyClient.json | abigen --abi - --type BeefyClient --pkg beefyclient --out beefyclient/contract.go" -//go:generate bash -c "jq .abi ../../core/packages/contracts/artifacts/contracts/BasicInboundChannel.sol/BasicInboundChannel.json | abigen --abi - --type BasicInboundChannel --pkg basic --out basic/inbound.go" -//go:generate bash -c "jq .abi ../../core/packages/contracts/artifacts/contracts/BasicOutboundChannel.sol/BasicOutboundChannel.json | abigen --abi - --type BasicOutboundChannel --pkg basic --out basic/outbound.go" +//go:generate bash -c "jq .abi ../../core/packages/contracts/out/OpaqueProof.sol/OpaqueProof.json | abigen --abi - --type OpaqueProof --pkg opaqueproof --out opaqueproof/contract.go" +//go:generate bash -c "jq .abi ../../core/packages/contracts/out/BeefyClient.sol/BeefyClient.json | abigen --abi - --type BeefyClient --pkg beefyclient --out beefyclient/contract.go" +//go:generate bash -c "jq .abi ../../core/packages/contracts/out/BasicInboundChannel.sol/BasicInboundChannel.json | abigen --abi - --type BasicInboundChannel --pkg basic --out basic/inbound.go" +//go:generate bash -c "jq .abi ../../core/packages/contracts/out/BasicOutboundChannel.sol/BasicOutboundChannel.json | abigen --abi - --type BasicOutboundChannel --pkg basic --out basic/outbound.go" package contracts diff --git a/relayer/go.mod b/relayer/go.mod index 5f5ce398fa..28b32177d8 100644 --- a/relayer/go.mod +++ b/relayer/go.mod @@ -8,7 +8,7 @@ require ( github.com/magefile/mage v1.13.0 github.com/sirupsen/logrus v1.8.1 github.com/snowfork/ethashproof v0.0.0-20210729080250-93b61cd82454 - github.com/snowfork/go-substrate-rpc-client/v4 v4.0.1-0.20230220165550-540414587385 + github.com/snowfork/go-substrate-rpc-client/v4 v4.0.1-0.20230222084249-a54344a28717 github.com/spf13/cobra v1.4.0 github.com/spf13/viper v1.12.0 github.com/stretchr/testify v1.8.0 diff --git a/relayer/go.sum b/relayer/go.sum index 300a69480a..839e3c2342 100644 --- a/relayer/go.sum +++ b/relayer/go.sum @@ -831,6 +831,8 @@ github.com/snowfork/go-substrate-rpc-client/v4 v4.0.1-0.20230220044419-4376f3e6a github.com/snowfork/go-substrate-rpc-client/v4 v4.0.1-0.20230220044419-4376f3e6a023/go.mod h1:MVk5+w9icYU7MViYFm7CKYhx1VMj6DpN2tWO6s4OK5g= github.com/snowfork/go-substrate-rpc-client/v4 v4.0.1-0.20230220165550-540414587385 h1:Tl5SWwJLIKASTKsv8F0Tg3iRAD3C4ORyJ4dMExoFZbs= github.com/snowfork/go-substrate-rpc-client/v4 v4.0.1-0.20230220165550-540414587385/go.mod h1:MVk5+w9icYU7MViYFm7CKYhx1VMj6DpN2tWO6s4OK5g= +github.com/snowfork/go-substrate-rpc-client/v4 v4.0.1-0.20230222084249-a54344a28717 h1:lU66MVEQbBjLFD6idyESqCr43+nFp5K78RWtyzfeIZg= +github.com/snowfork/go-substrate-rpc-client/v4 v4.0.1-0.20230222084249-a54344a28717/go.mod h1:MVk5+w9icYU7MViYFm7CKYhx1VMj6DpN2tWO6s4OK5g= 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= diff --git a/relayer/relays/beefy/ethereum-writer.go b/relayer/relays/beefy/ethereum-writer.go index 58a0e48a57..941f51ad25 100644 --- a/relayer/relays/beefy/ethereum-writer.go +++ b/relayer/relays/beefy/ethereum-writer.go @@ -259,7 +259,7 @@ func (wr *EthereumWriter) doSubmitInitial(ctx context.Context, task *Request) (* msg.Proof, ) if err != nil { - return nil, nil, fmt.Errorf("initial submit: %w", err) + return nil, nil, fmt.Errorf("initial submit with handover: %w", err) } } else { tx, err = wr.contract.SubmitInitial( @@ -329,7 +329,7 @@ func (wr *EthereumWriter) doSubmitFinal(ctx context.Context, commitmentHash [32] log.WithField("txHash", tx.Hash().Hex()). WithFields(logFields). - Info("Sent SubmitFinal transaction") + Info("Sent SubmitFinalWithHandover transaction") return tx, nil } else { // revive:disable-line diff --git a/relayer/relays/beefy/polkadot-listener.go b/relayer/relays/beefy/polkadot-listener.go index b586dfd215..27c9d6e06b 100644 --- a/relayer/relays/beefy/polkadot-listener.go +++ b/relayer/relays/beefy/polkadot-listener.go @@ -105,7 +105,7 @@ func (li *PolkadotListener) scanCommitments( "blockNumber": result.SignedCommitment.Commitment.BlockNumber, "validatorSetID": result.SignedCommitment.Commitment.ValidatorSetID, }, - }).Info("Discarded commitment") + }).Warn("Discarded commitment with depth not fast forward") continue } diff --git a/relayer/relays/parachain/logger.go b/relayer/relays/parachain/logger.go index 42c1f2200d..fa3b8fa020 100644 --- a/relayer/relays/parachain/logger.go +++ b/relayer/relays/parachain/logger.go @@ -23,7 +23,7 @@ func (wr *EthereumWriter) logFieldsForBasicSubmission( params := log.Fields{ "message": log.Fields{ - "sourceID": Hex(message.SourceId[:]), + "sourceID": Hex(message.SourceID[:]), "nonce": message.Nonce, "payload": message.Payload, }, diff --git a/relayer/relays/parachain/types.go b/relayer/relays/parachain/types.go index 8c1f52e9c4..d9c4314bad 100644 --- a/relayer/relays/parachain/types.go +++ b/relayer/relays/parachain/types.go @@ -85,7 +85,7 @@ type BasicOutboundChannelMessage struct { func (m BasicOutboundChannelMessage) IntoInboundMessage() basic.BasicInboundChannelMessage { return basic.BasicInboundChannelMessage{ - SourceId: m.SourceID, + SourceID: m.SourceID, Nonce: (*big.Int)(&m.Nonce).Uint64(), Payload: m.Payload, }