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
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add delete cmd to database writer
  • Loading branch information
denalimarsh committed Apr 30, 2021
commit 21de204695523c385999a965ff1741213696ae65
10 changes: 10 additions & 0 deletions relayer/workers/beefyrelayer/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ type CmdType int
const (
Create CmdType = iota // 0
Update CmdType = iota // 1
Delete CmdType = iota // 2
)

type DatabaseCmd struct {
Expand Down Expand Up @@ -178,6 +179,9 @@ func (d *Database) writeLoop(ctx context.Context) error {
case Update:
d.log.Info("Updating item in database...")
d.DB.Model(&cmd.Info).Updates(cmd.Instructions)
case Delete:
d.log.Info("Deleting item from database...")
d.DB.Delete(&cmd.Info, cmd.Info.ID)
}
mutex.Unlock()
}
Expand All @@ -195,3 +199,9 @@ func (d *Database) GetItemByInitialVerificationTxHash(txHash common.Hash) *Beefy
d.DB.Take(&item, "initial_verification_tx_hash = ?", txHash)
return &item
}

func (d *Database) GetItemByFinalVerificationTxHash(txHash common.Hash) *BeefyRelayInfo {
var item BeefyRelayInfo
d.DB.Take(&item, "final_verification_tx_hash = ?", txHash)
return &item
}
9 changes: 9 additions & 0 deletions relayer/workers/beefyrelayer/store/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ func TestStore(t *testing.T) {
newItem := database.GetItemByInitialVerificationTxHash(hash)
assert.Equal(t, newItem.Status, store.InitialVerificationTxSent)
assert.Equal(t, newItem.InitialVerificationTxHash, hash)

// Pass delete command to write loop
deleteCmd := store.NewDatabaseCmd(&item, store.Delete, nil)
messages <- deleteCmd

time.Sleep(2 * time.Second)

deletedItem := database.GetItemByInitialVerificationTxHash(hash)
assert.Equal(t, deletedItem, &store.BeefyRelayInfo{})
}

func loadSampleBeefyRelayInfo() store.BeefyRelayInfo {
Expand Down