Skip to content

Commit

Permalink
Fix proven time (#33)
Browse files Browse the repository at this point in the history
* chore: add bindings/optimismportal.go

* feat: record onchain proven timestamp

* chore: remove staled line
  • Loading branch information
bendanzhentan authored Mar 14, 2024
1 parent df84810 commit 85bed6b
Show file tree
Hide file tree
Showing 5 changed files with 1,498 additions and 4 deletions.
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,17 @@ build-solidity:
forge build; \
popd;

bindings: build-solidity
bindings: bindings-L2StandardBridgeBot bindings-OptimismPortal

bindings-L2StandardBridgeBot: build-solidity
jq '.abi' contracts/out/L2StandardBridgeBot.sol/L2StandardBridgeBot.json > contracts/out/L2StandardBridgeBot.sol/L2StandardBridgeBot.abi; \
abigen --abi contracts/out/L2StandardBridgeBot.sol/L2StandardBridgeBot.abi --pkg bindings --type L2StandardBridgeBot --out bindings/L2StandardBridgeBot.go

bindings-OptimismPortal:
curl -o bindings/OptimismPortal.go https://raw.githubusercontent.com/ethereum-optimism/optimism/005be54bde97747b6f1669030721cd4e0c14bc69/op-bindings/bindings/optimismportal.go

.PHONY: \
bot \
build-go \
build-solidity
build-solidity \
bindings
2 changes: 2 additions & 0 deletions bindings/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

**Note that all files under this directory are autogenerated via `make bindings`. For details, please refer to ../Makefile.**
1,453 changes: 1,453 additions & 0 deletions bindings/optimismportal.go

Large diffs are not rendered by default.

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 85bed6b

Please sign in to comment.