Skip to content

Commit

Permalink
Regenerate binds & update package path
Browse files Browse the repository at this point in the history
  • Loading branch information
yrong committed Nov 6, 2024
1 parent 42bc03d commit 78dd144
Show file tree
Hide file tree
Showing 11 changed files with 179 additions and 2,294 deletions.
2 changes: 1 addition & 1 deletion relayer/cmd/generate_beacon_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ func getEthereumEvent(ctx context.Context, gatewayContract *contracts.Gateway, c
for event == nil {
log.Info("looking for Ethereum event")

iter, err := gatewayContract.FilterOutboundMessageAccepted(&opts, [][32]byte{channelID}, [][32]byte{})
iter, err := gatewayContract.FilterOutboundMessageAccepted(&opts)
if err != nil {
return nil, err
}
Expand Down
2,177 changes: 87 additions & 2,090 deletions relayer/contracts/gateway.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion relayer/generate.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:generate bash -c "jq .abi ../contracts/out/BeefyClient.sol/BeefyClient.json | abigen --abi - --type BeefyClient --pkg contracts --out contracts/beefy_client.go"
//go:generate bash -c "jq .abi ../contracts/out/IGateway.sol/IGateway.json | abigen --abi - --type Gateway --pkg contracts --out contracts/gateway.go"
//go:generate bash -c "jq .abi ../contracts/out/IGateway.sol/IGatewayV2.json | abigen --abi - --type Gateway --pkg contracts --out contracts/gateway.go"

package main
14 changes: 3 additions & 11 deletions relayer/relays/execution/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,16 +222,9 @@ func (r *Relay) fetchLatestParachainNonce() (uint64, error) {
return paraNonce, nil
}

// Todo: nonce deprecated
func (r *Relay) fetchEthereumNonce(ctx context.Context) (uint64, error) {
opts := bind.CallOpts{
Context: ctx,
}
_, ethOutboundNonce, err := r.gatewayContract.ChannelNoncesOf(&opts, r.config.Source.ChannelID)
if err != nil {
return 0, fmt.Errorf("fetch Gateway.ChannelNoncesOf(%v): %w", r.config.Source.ChannelID, err)
}

return ethOutboundNonce, nil
return 0, nil
}

const BlocksPerQuery = 4096
Expand Down Expand Up @@ -286,7 +279,7 @@ func (r *Relay) findEvents(
}

func (r *Relay) findEventsWithFilter(opts *bind.FilterOpts, channelID [32]byte, start uint64) (bool, []*contracts.GatewayOutboundMessageAccepted, error) {
iter, err := r.gatewayContract.FilterOutboundMessageAccepted(opts, [][32]byte{channelID}, [][32]byte{})
iter, err := r.gatewayContract.FilterOutboundMessageAccepted(opts)
if err != nil {
return false, nil, err
}
Expand Down Expand Up @@ -409,7 +402,6 @@ func (r *Relay) doSubmit(ctx context.Context, ev *contracts.GatewayOutboundMessa
"blockNumber": ev.Raw.BlockNumber,
"txHash": ev.Raw.TxHash.Hex(),
"txIndex": ev.Raw.TxIndex,
"channelID": types.H256(ev.ChannelID).Hex(),
})

nextBlockNumber := new(big.Int).SetUint64(ev.Raw.BlockNumber + 1)
Expand Down
6 changes: 3 additions & 3 deletions relayer/relays/parachain/beefy-listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type BeefyListener struct {
relaychainConn *relaychain.Connection
parachainConnection *parachain.Connection
paraID uint32
tasks chan<- *TaskV2
tasks chan<- *Task
scanner *Scanner
}

Expand All @@ -39,7 +39,7 @@ func NewBeefyListener(
ethereumConn *ethereum.Connection,
relaychainConn *relaychain.Connection,
parachainConnection *parachain.Connection,
tasks chan<- *TaskV2,
tasks chan<- *Task,
) *BeefyListener {
return &BeefyListener{
config: config,
Expand Down Expand Up @@ -320,7 +320,7 @@ func (li *BeefyListener) generateAndValidateParasHeadsMerkleProof(input *ProofIn
return &merkleProofData, paraHeads, nil
}

func (li *BeefyListener) waitAndSend(ctx context.Context, task *TaskV2, waitingPeriod uint64) error {
func (li *BeefyListener) waitAndSend(ctx context.Context, task *Task, waitingPeriod uint64) error {
paraNonce := (*task.MessageProofs)[0].Message.Nonce
log.Info(fmt.Sprintf("waiting for nonce %d to be picked up by another relayer", paraNonce))
var cnt uint64
Expand Down
15 changes: 7 additions & 8 deletions relayer/relays/parachain/ethereum-writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ type EthereumWriter struct {
config *SinkConfig
conn *ethereum.Connection
gateway *contracts.Gateway
tasks <-chan *TaskV2
tasks <-chan *Task
gatewayABI abi.ABI
relayConfig *Config
}

func NewEthereumWriter(
config *SinkConfig,
conn *ethereum.Connection,
tasks <-chan *TaskV2,
tasks <-chan *Task,
relayConfig *Config,
) (*EthereumWriter, error) {
return &EthereumWriter{
Expand Down Expand Up @@ -97,7 +97,7 @@ func (wr *EthereumWriter) writeMessagesLoop(ctx context.Context) error {
func (wr *EthereumWriter) WriteChannels(
ctx context.Context,
options *bind.TransactOpts,
task *TaskV2,
task *Task,
) error {
for _, proof := range *task.MessageProofs {
err := wr.WriteChannel(ctx, options, &proof, task.ProofOutput)
Expand All @@ -113,10 +113,10 @@ func (wr *EthereumWriter) WriteChannels(
func (wr *EthereumWriter) WriteChannel(
ctx context.Context,
options *bind.TransactOpts,
commitmentProof *MessageProofV2,
commitmentProof *MessageProof,
proof *ProofOutput,
) error {
message := commitmentProof.Message.IntoInboundMessageV2()
message := commitmentProof.Message.IntoInboundMessage()

convertedHeader, err := convertHeader(proof.Header)
if err != nil {
Expand Down Expand Up @@ -192,9 +192,8 @@ func (wr *EthereumWriter) WriteChannel(
return fmt.Errorf("unpack event log: %w", err)
}
log.WithFields(log.Fields{
"channelID": Hex(holder.ChannelID[:]),
"nonce": holder.Nonce,
"success": holder.Success,
"nonce": holder.Nonce,
"success": holder.Success,
}).Info("Message dispatched")
}
}
Expand Down
2 changes: 1 addition & 1 deletion relayer/relays/parachain/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func Hex(b []byte) string {
}

func (wr *EthereumWriter) logFieldsForSubmission(
message contracts.InboundMessageV2,
message contracts.InboundMessage,
messageProof [][32]byte,
proof contracts.VerificationProof,
) log.Fields {
Expand Down
12 changes: 6 additions & 6 deletions relayer/relays/parachain/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func NewRelay(config *Config, keypair *secp256k1.Keypair, keypair2 *sr25519.Keyp
ethereumConnBeefy := ethereum.NewConnection(&config.Source.Ethereum, keypair)

// channel for messages from beefy listener to ethereum writer
var tasks = make(chan *TaskV2, 1)
var tasks = make(chan *Task, 1)

ethereumChannelWriter, err := NewEthereumWriter(
&config.Sink,
Expand Down Expand Up @@ -189,11 +189,11 @@ func (relay *Relay) startDeliverProof(ctx context.Context, eg *errgroup.Group) e
func (relay *Relay) findEvent(
ctx context.Context,
nonce uint64,
) (*contracts.GatewayInboundMessageDispatched0, error) {
) (*contracts.GatewayInboundMessageDispatched, error) {

const BlocksPerQuery = 4096

var event *contracts.GatewayInboundMessageDispatched0
var event *contracts.GatewayInboundMessageDispatched

blockNumber, err := relay.ethereumConnWriter.Client().BlockNumber(ctx)
if err != nil {
Expand Down Expand Up @@ -221,7 +221,7 @@ func (relay *Relay) findEvent(
Context: ctx,
}

iter, err := relay.ethereumChannelWriter.gateway.FilterInboundMessageDispatched0(&opts, []uint64{nonce}, [][32]byte{rewardAddress})
iter, err := relay.ethereumChannelWriter.gateway.FilterInboundMessageDispatched(&opts, []uint64{nonce}, [][32]byte{rewardAddress})
if err != nil {
return event, fmt.Errorf("iter dispatch event: %w", err)
}
Expand Down Expand Up @@ -259,7 +259,7 @@ func (relay *Relay) findEvent(
func (relay *Relay) makeInboundMessage(
ctx context.Context,
headerCache *ethereum.HeaderCache,
event *contracts.GatewayInboundMessageDispatched0,
event *contracts.GatewayInboundMessageDispatched,
) (*parachain.Message, error) {
receiptTrie, err := headerCache.GetReceiptTrie(ctx, event.Raw.BlockHash)
if err != nil {
Expand Down Expand Up @@ -291,7 +291,7 @@ func (relay *Relay) makeInboundMessage(
return msg, nil
}

func (relay *Relay) doSubmit(ctx context.Context, ev *contracts.GatewayInboundMessageDispatched0) error {
func (relay *Relay) doSubmit(ctx context.Context, ev *contracts.GatewayInboundMessageDispatched) error {
inboundMsg, err := relay.makeInboundMessage(ctx, relay.headerCache, ev)
if err != nil {
return fmt.Errorf("make outgoing message: %w", err)
Expand Down
33 changes: 16 additions & 17 deletions relayer/relays/parachain/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@ type Scanner struct {
relayConn *relaychain.Connection
paraConn *parachain.Connection
paraID uint32
tasks chan<- *Task
}

// Scans for all parachain message commitments that need to be relayed and can be
// proven using the MMR root at the specified beefyBlockNumber of the relay chain.
// The algorithm fetch PendingOrders storage in OutboundQueue of BH and
// just relay each order which has not been processed on Ethereum yet.
func (s *Scanner) Scan(ctx context.Context, beefyBlockNumber uint64) ([]*TaskV2, error) {
func (s *Scanner) Scan(ctx context.Context, beefyBlockNumber uint64) ([]*Task, error) {
// fetch last parachain header that was finalized *before* the BEEFY block
beefyBlockMinusOneHash, err := s.relayConn.API().RPC.Chain.GetBlockHash(uint64(beefyBlockNumber - 1))
if err != nil {
Expand Down Expand Up @@ -64,7 +63,7 @@ func (s *Scanner) Scan(ctx context.Context, beefyBlockNumber uint64) ([]*TaskV2,
func (s *Scanner) findTasks(
ctx context.Context,
paraHash types.Hash,
) ([]*TaskV2, error) {
) ([]*Task, error) {
// Fetch PendingOrders storage in parachain outbound queue
storageKey := types.NewStorageKey(types.CreateStorageKeyPrefix("EthereumOutboundQueueV2", "PendingOrders"))
keys, err := s.paraConn.API().RPC.State.GetKeys(storageKey, paraHash)
Expand Down Expand Up @@ -103,9 +102,9 @@ func (s *Scanner) findTasks(
func (s *Scanner) findTasksImpl(
ctx context.Context,
pendingNonces []PendingOrder,
) ([]*TaskV2, error) {
) ([]*Task, error) {

var tasks []*TaskV2
var tasks []*Task

for _, pending := range pendingNonces {

Expand Down Expand Up @@ -149,7 +148,7 @@ func (s *Scanner) findTasksImpl(
continue
}

var messages []OutboundQueueMessageV2
var messages []OutboundQueueMessage
raw, err := s.paraConn.API().RPC.State.GetStorageRaw(messagesKey, blockHash)
if err != nil {
return nil, fmt.Errorf("fetch committed messages for block %v: %w", blockHash.Hex(), err)
Expand All @@ -160,7 +159,7 @@ func (s *Scanner) findTasksImpl(
return nil, fmt.Errorf("decode message length error: %w", err)
}
for i := uint64(0); i < n.Uint64(); i++ {
m := OutboundQueueMessageV2{}
m := OutboundQueueMessage{}
err = decoder.Decode(&m)
if err != nil {
return nil, fmt.Errorf("decode message error: %w", err)
Expand All @@ -182,7 +181,7 @@ func (s *Scanner) findTasksImpl(
}

if len(result.proofs) > 0 {
task := TaskV2{
task := Task{
Header: header,
MessageProofs: &result.proofs,
ProofInput: nil,
Expand All @@ -205,7 +204,7 @@ type PersistedValidationData struct {
// For each task, gatherProofInputs will search to find the relay chain block
// in which that header was included as well as the parachain heads for that block.
func (s *Scanner) gatherProofInputs(
tasks []*TaskV2,
tasks []*Task,
) error {
for _, task := range tasks {

Expand Down Expand Up @@ -294,11 +293,11 @@ func scanForOutboundQueueProofs(
api *gsrpc.SubstrateAPI,
blockHash types.Hash,
commitmentHash types.H256,
messages []OutboundQueueMessageV2,
messages []OutboundQueueMessage,
) (*struct {
proofs []MessageProofV2
proofs []MessageProof
}, error) {
proofs := []MessageProofV2{}
proofs := []MessageProof{}

for i := len(messages) - 1; i >= 0; i-- {
message := messages[i]
Expand All @@ -321,7 +320,7 @@ func scanForOutboundQueueProofs(
}

return &struct {
proofs []MessageProofV2
proofs []MessageProof
}{
proofs: proofs,
}, nil
Expand All @@ -331,10 +330,10 @@ func fetchMessageProof(
api *gsrpc.SubstrateAPI,
blockHash types.Hash,
messageIndex uint64,
message OutboundQueueMessageV2,
) (MessageProofV2, error) {
message OutboundQueueMessage,
) (MessageProof, error) {
var proofHex string
var proof MessageProofV2
var proof MessageProof

params, err := types.EncodeToHexString(messageIndex)
if err != nil {
Expand All @@ -361,7 +360,7 @@ func fetchMessageProof(
return proof, fmt.Errorf("decode merkle proof: %w", err)
}

return MessageProofV2{Message: message, Proof: merkleProof}, nil
return MessageProof{Message: message, Proof: merkleProof}, nil
}

func (s *Scanner) isNonceRelayed(ctx context.Context, nonce uint64) (bool, error) {
Expand Down
Loading

0 comments on commit 78dd144

Please sign in to comment.