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

Fix proven time #33

Merged
merged 3 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
12 changes: 10 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,19 @@ build-solidity:
forge build; \
popd;

bindings: build-solidity
https://raw.githubusercontent.com/ethereum-optimism/optimism/005be54bde97747b6f1669030721cd4e0c14bc69/op-bindings/bindings/optimismportal.go
owen-reorg marked this conversation as resolved.
Show resolved Hide resolved

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
Loading