Skip to content

Commit

Permalink
feat: record onchain proven timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
bendanzhentan committed Mar 9, 2024
1 parent fadc9d4 commit 41c94a8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
8 changes: 6 additions & 2 deletions cmd/bot/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,16 @@ func ProcessUnprovenBotDelegatedWithdrawals(ctx context.Context, log log.Logger,
continue
}

now := time.Now()
err := processor.ProveWithdrawalTransaction(ctx, &unproven, *currentNonce)
if err != nil {
if strings.Contains(err.Error(), "OptimismPortal: withdrawal hash has already been proven") {
// The withdrawal has already proven, mark it
result := db.Model(&unproven).Update("proven_time", now)
provenTime, err := processor.GetProvenTime(&unproven)
if err != nil {
log.Error("fail to get proven time", "error", err)
}

result := db.Model(&unproven).Update("proven_time", provenTime)
if result.Error != nil {
log.Error("failed to update proven withdrawals", "error", result.Error)
}
Expand Down
29 changes: 29 additions & 0 deletions core/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,35 @@ func (b *Processor) FinalizeMessage(ctx context.Context, wi *WithdrawalInitiated
return nil
}

func (b *Processor) GetProvenTime(wi *WithdrawalInitiatedLog) (*big.Int, error) {
optimismPortal, err := bindings.NewOptimismPortalCaller(b.cfg.L1Contracts.OptimismPortalProxy, b.L1Client)
if err != nil {
return nil, err
}

receipt, err := b.L1Client.TransactionReceipt(context.Background(), common.HexToHash(wi.TransactionHash))
if err != nil {
return nil, err
}

withdrawal, err := b.toWithdrawal(wi, receipt)
if err != nil {
return nil, err
}

withdrawalHash, err := b.hashWithdrawal(withdrawal)
if err != nil {
return nil, err
}

provenWithdrawal, err := optimismPortal.ProvenWithdrawals(nil, common.HexToHash(withdrawalHash))
if err != nil {
return nil, err
}

return provenWithdrawal.Timestamp, nil
}

func (b *Processor) hashWithdrawal(w *bindings.TypesWithdrawalTransaction) (string, error) {
uint256Type, _ := abi.NewType("uint256", "", nil)
addressType, _ := abi.NewType("address", "", nil)
Expand Down

0 comments on commit 41c94a8

Please sign in to comment.