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

Sync Relayer from previous Ethereum block #384

Merged
merged 16 commits into from
Jun 1, 2021
Merged
Prev Previous commit
Next Next commit
update beefy eth writer
  • Loading branch information
denalimarsh committed Apr 30, 2021
commit b7e370442da28dedd1ee76b560c67ca41169635e
17 changes: 9 additions & 8 deletions relayer/workers/beefyrelayer/beefy-ethereum-writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ type BeefyEthereumWriter struct {

func NewBeefyEthereumWriter(ethereumConfig *ethereum.Config, ethereumConn *ethereum.Connection, beefyDB *store.Database,
databaseMessages chan<- store.DatabaseCmd, beefyMessages <-chan store.BeefyRelayInfo,
log *logrus.Entry) *BeefyEthereumWriter {
log *logrus.Entry) (*BeefyEthereumWriter, error) {
return &BeefyEthereumWriter{
ethereumConfig: ethereumConfig,
ethereumConn: ethereumConn,
beefyDB: beefyDB,
databaseMessages: databaseMessages,
beefyMessages: beefyMessages,
log: log,
}
}, nil
}

func (wr *BeefyEthereumWriter) Start(ctx context.Context, eg *errgroup.Group) error {
Expand Down Expand Up @@ -128,10 +128,12 @@ func (wr *BeefyEthereumWriter) WriteNewSignatureCommitment(ctx context.Context,
"txHash": tx.Hash().Hex(),
}).Info("New Signature Commitment transaction submitted")

wr.log.Info("1: Creating item in Database with status 'InitialVerificationTxSent'")
info.Status = store.InitialVerificationTxSent
info.InitialVerificationTxHash = tx.Hash()
cmd := store.NewDatabaseCmd(&info, store.Create, nil)
wr.log.Info("2: Updating item in Database with status 'InitialVerificationTxSent'")
instructions := map[string]interface{}{
"status": store.InitialVerificationTxSent,
"initial_verification_tx_hash": tx.Hash(),
}
cmd := store.NewDatabaseCmd(&info, store.Update, instructions)
wr.databaseMessages <- cmd

return nil
Expand Down Expand Up @@ -174,14 +176,13 @@ func (wr *BeefyEthereumWriter) WriteCompleteSignatureCommitment(ctx context.Cont
}).Info("Complete Signature Commitment transaction submitted")

// Update item's status in database
wr.log.Info("4: Updating item status from 'ReadyToComplete' to 'CompleteVerificationTxSent'")
wr.log.Info("5: Updating item status from 'ReadyToComplete' to 'CompleteVerificationTxSent'")
instructions := map[string]interface{}{
"status": store.CompleteVerificationTxSent,
"complete_verification_tx_hash": tx.Hash(),
}
updateCmd := store.NewDatabaseCmd(&info, store.Update, instructions)
wr.databaseMessages <- updateCmd

// TODO: delete from database after confirming
return nil
}