Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
43 changes: 27 additions & 16 deletions oracle/pkg/updater/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ func checkPositionConstraintSatisfied(
}
}
case bidderapiv1.PositionConstraint_BASIS_GAS_PERCENTILE:
if txnDetails.TotalGas == 0 {
return false
}
gasUsed := gasUsedUntil(txnDetails.PosInBlock, txns)
gasPercentile := (gasUsed * 100) / txnDetails.TotalGas
txnGasPercentile := (txnDetails.GasUsed * 100) / txnDetails.TotalGas
Expand Down Expand Up @@ -302,14 +305,17 @@ func (u *Updater) handleOpenedCommitment(
)

commitmentTxnHashes := strings.Split(update.TxnHash, ",")
for i, h := range commitmentTxnHashes {
commitmentTxnHashes[i] = strings.TrimPrefix(strings.TrimSpace(h), "0x")
}
u.logger.Debug("commitmentTxnHashes", "commitmentTxnHashes", commitmentTxnHashes)
revertableTxns := strings.Split(update.RevertingTxHashes, ",")
u.logger.Debug("revertableTxns", "revertableTxns", revertableTxns)

// Create a map for revertable transactions
revertableTxnsMap := make(map[string]bool)
for _, txn := range revertableTxns {
revertableTxnsMap[txn] = true
revertableTxnsMap[strings.TrimPrefix(strings.TrimSpace(txn), "0x")] = true
}

var opts *bidderapiv1.BidOptions
Expand Down Expand Up @@ -371,22 +377,23 @@ func (u *Updater) handleOpenedCommitment(
}

if u.bidOptionsSlashEnabled {
for idx, opt := range opts.Options {
if opt.GetPositionConstraint() != nil {
if checkPositionConstraintSatisfied(opt.GetPositionConstraint(), txnDetails, txns) {
u.logger.Debug(
"positional constraint satisfied",
"commitmentIdx", common.Bytes2Hex(update.CommitmentIndex[:]),
"txnHash", update.TxnHash,
"blockNumber", update.BlockNumber,
"constraint", opt.GetPositionConstraint(),
)
// Remove the satisfied constraint
opts.Options = append(opts.Options[:idx], opts.Options[idx+1:]...)
break
}
var remaining []*bidderapiv1.BidOption
satisfied := false
for _, opt := range opts.Options {
if !satisfied && opt.GetPositionConstraint() != nil && checkPositionConstraintSatisfied(opt.GetPositionConstraint(), txnDetails, txns) {
u.logger.Debug(
"positional constraint satisfied",
"commitmentIdx", common.Bytes2Hex(update.CommitmentIndex[:]),
"txnHash", update.TxnHash,
"blockNumber", update.BlockNumber,
"constraint", opt.GetPositionConstraint(),
)
satisfied = true
} else {
remaining = append(remaining, opt)
}
}
opts.Options = remaining
}
}

Expand Down Expand Up @@ -556,7 +563,11 @@ func (u *Updater) getL1Txns(ctx context.Context, blockNum uint64) (map[string]Tx
u.logger.Debug("received batch receipts", "duration", time.Since(start).Seconds())
for _, result := range results {
if result.Err != nil {
u.logger.Error("failed to get receipt for txn", "txnHash", result.Receipt.TxHash.Hex(), "error", result.Err)
txnHashStr := "unknown"
if result.Receipt != nil {
txnHashStr = result.Receipt.TxHash.Hex()
}
u.logger.Error("failed to get receipt for txn", "txnHash", txnHashStr, "error", result.Err)
continue
}

Expand Down
2 changes: 1 addition & 1 deletion x/contracts/txmonitor/eth_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (e *EVMHelperImpl) BatchReceipts(ctx context.Context, txHashes []common.Has
for attempts := 0; attempts < 50; attempts++ {
e.logger.Debug("Attempting batch call", "attempt", attempts+1)
// Execute the batch request
err = e.client.Client().BatchCallContext(context.Background(), batch)
err = e.client.Client().BatchCallContext(ctx, batch)
if err != nil {
e.logger.Error("Batch call attempt failed", "attempt", attempts+1, "error", err)
time.Sleep(1 * time.Second)
Expand Down