Skip to content

Commit

Permalink
Merge pull request #65 from alexgao001/fix-outturn-relaying
Browse files Browse the repository at this point in the history
fix: outturn relayer should only rely on chain's sequence
  • Loading branch information
unclezoro authored Jul 31, 2023
2 parents 17c7fb3 + a229c20 commit ddec932
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 16 deletions.
28 changes: 19 additions & 9 deletions assembler/bsc_assembler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down
26 changes: 19 additions & 7 deletions assembler/greenfield_assembler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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++ {
Expand Down

0 comments on commit ddec932

Please sign in to comment.