From a229c2047b9ecb48cb09ea284fdb3f81ca3251c0 Mon Sep 17 00:00:00 2001 From: Alexgao001 Date: Thu, 27 Jul 2023 22:38:41 +0800 Subject: [PATCH] outturn relayer should rely on chain's sequence --- assembler/bsc_assembler.go | 28 +++++++++++++++++++--------- assembler/greenfield_assembler.go | 26 +++++++++++++++++++------- 2 files changed, 38 insertions(+), 16 deletions(-) diff --git a/assembler/bsc_assembler.go b/assembler/bsc_assembler.go index 34279e6..47ba6b8 100644 --- a/assembler/bsc_assembler.go +++ b/assembler/bsc_assembler.go @@ -70,7 +70,11 @@ func (a *BSCAssembler) process(channelId types.ChannelId) error { isInturnRelyer := bytes.Equal(a.blsPubKey, inturnRelayerPubkey) a.metricService.SetGnfdInturnRelayerMetrics(isInturnRelyer, inturnRelayer.RelayInterval.Start, inturnRelayer.RelayInterval.End) - var startSeq uint64 + + var ( + startSeq uint64 + endSequence int64 + ) if isInturnRelyer { if !a.inturnRelayerSequenceStatus.HasRetrieved { @@ -115,13 +119,20 @@ func (a *BSCAssembler) process(channelId types.ChannelId) error { if err != nil { return err } - - endSequence, err := a.daoManager.BSCDao.GetLatestOracleSequenceByStatus(db.AllVoted) - if err != nil { - return err - } - if endSequence == -1 { - return nil + if isInturnRelyer { + endSequence, err = a.daoManager.BSCDao.GetLatestOracleSequenceByStatus(db.AllVoted) + if err != nil { + return err + } + if endSequence == -1 { + return nil + } + } else { + endSeq, err := a.bscExecutor.GetNextSendSequenceForChannelWithRetry() + if err != nil { + return err + } + endSequence = int64(endSeq) } logging.Logger.Debugf("start seq and end enq are %d and %d", startSeq, endSequence) @@ -176,7 +187,6 @@ func (a *BSCAssembler) process(channelId types.ChannelId) error { func (a *BSCAssembler) processPkgs(client *executor.GreenfieldClient, pkgs []*model.BscRelayPackage, channelId uint8, sequence uint64, nonce uint64, isInturnRelyer bool) error { // Get votes result for a packages, which are already validated and qualified to aggregate sig - votes, err := a.daoManager.VoteDao.GetVotesByChannelIdAndSequence(channelId, sequence) if err != nil { logging.Logger.Errorf("failed to get votes result for packages for channel %d and sequence %d", channelId, sequence) diff --git a/assembler/greenfield_assembler.go b/assembler/greenfield_assembler.go index 1bb018d..2c2bbd4 100644 --- a/assembler/greenfield_assembler.go +++ b/assembler/greenfield_assembler.go @@ -97,7 +97,10 @@ func (a *GreenfieldAssembler) assembleTransactionAndSendForChannel(channelId typ } func (a *GreenfieldAssembler) process(channelId types.ChannelId, inturnRelayer *types.InturnRelayer, isInturnRelyer bool) error { - var startSeq uint64 + var ( + startSeq uint64 + endSequence int64 + ) if isInturnRelyer { if !a.inturnRelayerSequenceStatusMap[channelId].HasRetrieved { @@ -136,13 +139,22 @@ func (a *GreenfieldAssembler) process(channelId types.ChannelId, inturnRelayer * return err } - endSequence, err := a.daoManager.GreenfieldDao.GetLatestSequenceByChannelIdAndStatus(channelId, db.AllVoted) - if err != nil { - return err - } - if endSequence == -1 { - return nil + if isInturnRelyer { + endSequence, err = a.daoManager.GreenfieldDao.GetLatestSequenceByChannelIdAndStatus(channelId, db.AllVoted) + if err != nil { + return err + } + if endSequence == -1 { + return nil + } + } else { + endSeq, err := a.greenfieldExecutor.GetNextSendSequenceForChannelWithRetry(channelId) + if err != nil { + return err + } + endSequence = int64(endSeq) } + logging.Logger.Debugf("channel %d start seq and end enq are %d and %d", channelId, startSeq, endSequence) for i := startSeq; i <= uint64(endSequence); i++ {