Skip to content

Commit

Permalink
fix: fix missing orders (#163)
Browse files Browse the repository at this point in the history
# Description

## Context
@elena-zh create a TWAP tx that didn't get index in watch tower.

https://basescan.org/tx/0xa9e88af5dee1d51f217bbe7613e2897cec6b3d989e8f3cab5142aa74ccb96278#eventlog

I saw there was not logs for that transaction. Which is odd! I can see
the event for conditional order created.
During my test, my transaction was indexed. 

https://basescan.org/tx/0xf0a848e6899330e84e86160f079cf341b145b1fb2bbc2f7a8aec1dfb425384c9#eventlog

In principle both TX emit the same event, and should have been picked in
the same way, but something was making us to skip some indexing of
events

## Cause
I reviewed the code and saw some changes applied 2 months ago were
making us skip the indexing of events for some blocks.

See:
https://github.com/cowprotocol/watch-tower/pull/161/files#r1862591918

## Solution
Bring back the code that skips the polling of tradable orders from the
handlers, but leaves the indexing of conditional orders (so we don't
miss an order creation and we can do the polling in a future block).


<img width="1714" alt="image"
src="https://github.com/user-attachments/assets/ab8f7773-ad07-420c-a9e5-7256a71bb578">
  • Loading branch information
anxolin authored Nov 28, 2024
1 parent 4feaf45 commit 994d99d
Showing 1 changed file with 24 additions and 27 deletions.
51 changes: 24 additions & 27 deletions src/services/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,15 +320,6 @@ export class ChainContext {
let lastBlockReceived = lastProcessedBlock;
provider.on("block", async (blockNumber: number) => {
try {
// Decide if we should process this block before polling for events
const shouldProcessBlock =
blockNumber % this.processEveryNumBlocks === 0;

if (!shouldProcessBlock) {
log.debug(`Skipping block ${blockNumber}`);
return;
}

log.debug(`New block ${blockNumber}`);

const block = await provider.getBlock(blockNumber);
Expand Down Expand Up @@ -453,10 +444,11 @@ async function processBlock(
blockNumberOverride?: number,
blockTimestampOverride?: number
) {
const { provider, chainId } = context;
const { provider, chainId, processEveryNumBlocks } = context;
const timer = metrics.processBlockDurationSeconds
.labels(context.chainId.toString())
.startTimer();

const log = getLogger(
"chainContext:processBlock",
chainId.toString(),
Expand All @@ -482,24 +474,29 @@ async function processBlock(
}
}

// Decide if we should process this block
const shouldProcessBlock = block.number % processEveryNumBlocks === 0;

// Check programmatic orders and place orders if necessary
const result = await checkForAndPlaceOrder(
context,
block,
blockNumberOverride,
blockTimestampOverride
)
.then(() => true)
.catch(() => {
hasErrors = true;
log.error(`Error running "checkForAndPlaceOrder" action`);
return false;
});
log.debug(
`Result of "checkForAndPlaceOrder" action for block ${
block.number
}: ${_formatResult(result)}`
);
if (shouldProcessBlock) {
const result = await checkForAndPlaceOrder(
context,
block,
blockNumberOverride,
blockTimestampOverride
)
.then(() => true)
.catch(() => {
hasErrors = true;
log.error(`Error running "checkForAndPlaceOrder" action`);
return false;
});
log.debug(
`Result of "checkForAndPlaceOrder" action for block ${
block.number
}: ${_formatResult(result)}`
);
}

timer();

Expand Down

0 comments on commit 994d99d

Please sign in to comment.