Skip to content

Commit

Permalink
fix: temp fix, skip fillDeadlineBuffer call in proposer (#1214)
Browse files Browse the repository at this point in the history
* fix: temp fix, skip fillDeadlineBuffer call in proposer

* Update Dataworker.blockRangeUtils.ts

* Update DataworkerUtils.ts
  • Loading branch information
nicholaspai authored Feb 21, 2024
1 parent 63b5bf9 commit 23f63d3
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 104 deletions.
18 changes: 6 additions & 12 deletions src/dataworker/DataworkerUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,18 +129,12 @@ export async function blockRangesAreInvalidForSpokeClients(
return true;
}

if (endBlockTimestamps !== undefined) {
// TODO: Change this to query the max fill deadline between the values at the start and the end block after
// we've fully migrated to V3. This is set to only query at the end block right now to deal with the
// V2 to V3 migration bundle that contains a start block prior to the V3 upgrade. At this block, the
// fill deadline buffer will not be in the SpokePool Proxy's ABI so it will fail. We could handle this dynamically
// but because its a one-time change and I think the fill deadline buffer is unlikely to change during this
// bundle, that this is a safe temporary fix.
const maxFillDeadlineBufferInBlockRange = await spokePoolClient.getMaxFillDeadlineInRange(/* start*/ end, end);
if (endBlockTimestamps[chainId] - spokePoolClient.getOldestTime() < maxFillDeadlineBufferInBlockRange) {
return true;
}
}
// if (endBlockTimestamps !== undefined) {
// const maxFillDeadlineBufferInBlockRange = await spokePoolClient.getMaxFillDeadlineInRange(start, end);
// if (endBlockTimestamps[chainId] - spokePoolClient.getOldestTime() < maxFillDeadlineBufferInBlockRange) {
// return true;
// }
// }
// We must now assume that all newly expired deposits at the time of the bundle end blocks are contained within
// the spoke pool client's memory.

Expand Down
182 changes: 90 additions & 92 deletions test/Dataworker.blockRangeUtils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ethers, expect, smock } from "./utils";
import { ethers, expect } from "./utils";
import { setupDataworker } from "./fixtures/Dataworker.Fixture";

// Tested
Expand All @@ -8,9 +8,7 @@ import { getWidestPossibleExpectedBlockRange } from "../src/dataworker/PoolRebal
import { originChainId } from "./constants";
import { blockRangesAreInvalidForSpokeClients, getEndBlockBuffers } from "../src/dataworker/DataworkerUtils";
import { getDeployedBlockNumber } from "@across-protocol/contracts-v2";
import { MockHubPoolClient, MockSpokePoolClient } from "./mocks";
import { getTimestampsForBundleEndBlocks } from "../src/utils/BlockUtils";
import { assert } from "../src/utils";
import { MockHubPoolClient } from "./mocks";

let dataworkerClients: DataworkerClients;
let spokePoolClients: { [chainId: number]: SpokePoolClient };
Expand Down Expand Up @@ -154,7 +152,7 @@ describe("Dataworker block range-related utility methods", async function () {
// Only use public chain IDs because getDeploymentBlockNumber will only work for real chain ID's. This is a hack
// and getDeploymentBlockNumber should be changed to work in test environments.
const _spokePoolClients = { [chainId]: spokePoolClients[chainId] };
let chainIds = [chainId];
const chainIds = [chainId];

// Look if bundle range from block is before the latest invalid
// bundle start block. If so, then the range is invalid.
Expand Down Expand Up @@ -254,96 +252,96 @@ describe("Dataworker block range-related utility methods", async function () {
)
).to.equal(false);

// Override spoke pool client fill deadline buffer and oldest time searched and check that it returns false
// buffer if not great enough to cover the time between the end block and the oldest time searched by
// the client.
const originSpokePoolClient = spokePoolClients[originChainId];
chainIds = [originChainId];
// // Override spoke pool client fill deadline buffer and oldest time searched and check that it returns false
// // buffer if not great enough to cover the time between the end block and the oldest time searched by
// // the client.
// const originSpokePoolClient = spokePoolClients[originChainId];
// chainIds = [originChainId];

// Create a fake spoke pool so we can manipulate the fill deadline buffer. Make sure it returns a realistic
// current time so that computing bundle end block timestamps gives us realistic numbers.
const fakeSpokePool = await smock.fake(originSpokePoolClient.spokePool.interface);
fakeSpokePool.getCurrentTime.returns(originSpokePoolClient.currentTime);
const mockSpokePoolClient = new MockSpokePoolClient(
originSpokePoolClient.logger,
fakeSpokePool,
originSpokePoolClient.chainId,
originSpokePoolClient.deploymentBlock
);
const blockRanges = [[mainnetDeploymentBlock + 1, mockSpokePoolClient.latestBlockSearched]];
const endBlockTimestamps = await getTimestampsForBundleEndBlocks(
{ [originChainId]: mockSpokePoolClient as SpokePoolClient },
blockRanges,
chainIds
);
// override oldest spoke pool client's oldest time searched to be realistic (i.e. not zero)
mockSpokePoolClient.setOldestBlockTimestampOverride(originSpokePoolClient.getOldestTime());
const expectedTimeBetweenOldestAndEndBlockTimestamp =
endBlockTimestamps[originChainId] - mockSpokePoolClient.getOldestTime();
assert(
expectedTimeBetweenOldestAndEndBlockTimestamp > 0,
"unrealistic time between oldest and end block timestamp"
);
const fillDeadlineOverride = expectedTimeBetweenOldestAndEndBlockTimestamp + 1;
mockSpokePoolClient.setMaxFillDeadlineOverride(fillDeadlineOverride);
expect(
await blockRangesAreInvalidForSpokeClients(
{ [originChainId]: mockSpokePoolClient as SpokePoolClient },
blockRanges,
chainIds,
{
[originChainId]: mainnetDeploymentBlock,
},
true // isV3
)
).to.equal(true);
// // Create a fake spoke pool so we can manipulate the fill deadline buffer. Make sure it returns a realistic
// // current time so that computing bundle end block timestamps gives us realistic numbers.
// const fakeSpokePool = await smock.fake(originSpokePoolClient.spokePool.interface);
// fakeSpokePool.getCurrentTime.returns(originSpokePoolClient.currentTime);
// const mockSpokePoolClient = new MockSpokePoolClient(
// originSpokePoolClient.logger,
// fakeSpokePool,
// originSpokePoolClient.chainId,
// originSpokePoolClient.deploymentBlock
// );
// const blockRanges = [[mainnetDeploymentBlock + 1, mockSpokePoolClient.latestBlockSearched]];
// const endBlockTimestamps = await getTimestampsForBundleEndBlocks(
// { [originChainId]: mockSpokePoolClient as SpokePoolClient },
// blockRanges,
// chainIds
// );
// // override oldest spoke pool client's oldest time searched to be realistic (i.e. not zero)
// mockSpokePoolClient.setOldestBlockTimestampOverride(originSpokePoolClient.getOldestTime());
// const expectedTimeBetweenOldestAndEndBlockTimestamp =
// endBlockTimestamps[originChainId] - mockSpokePoolClient.getOldestTime();
// assert(
// expectedTimeBetweenOldestAndEndBlockTimestamp > 0,
// "unrealistic time between oldest and end block timestamp"
// );
// const fillDeadlineOverride = expectedTimeBetweenOldestAndEndBlockTimestamp + 1;
// mockSpokePoolClient.setMaxFillDeadlineOverride(fillDeadlineOverride);
// expect(
// await blockRangesAreInvalidForSpokeClients(
// { [originChainId]: mockSpokePoolClient as SpokePoolClient },
// blockRanges,
// chainIds,
// {
// [originChainId]: mainnetDeploymentBlock,
// },
// true // isV3
// )
// ).to.equal(true);

// Should be valid if not V3
expect(
await blockRangesAreInvalidForSpokeClients(
{ [originChainId]: mockSpokePoolClient as SpokePoolClient },
blockRanges,
chainIds,
{
[originChainId]: mainnetDeploymentBlock,
},
false // isV3
)
).to.equal(false);
// // Should be valid if not V3
// expect(
// await blockRangesAreInvalidForSpokeClients(
// { [originChainId]: mockSpokePoolClient as SpokePoolClient },
// blockRanges,
// chainIds,
// {
// [originChainId]: mainnetDeploymentBlock,
// },
// false // isV3
// )
// ).to.equal(false);

// Set oldest time older such that fill deadline buffer now exceeds the time between the end block and the oldest
// time. Block ranges should now be valid.
const oldestBlockTimestampOverride = endBlockTimestamps[originChainId] - fillDeadlineOverride - 1;
assert(oldestBlockTimestampOverride > 0, "unrealistic oldest block timestamp");
mockSpokePoolClient.setOldestBlockTimestampOverride(oldestBlockTimestampOverride);
expect(
await blockRangesAreInvalidForSpokeClients(
{ [originChainId]: mockSpokePoolClient as SpokePoolClient },
blockRanges,
chainIds,
{
[originChainId]: mainnetDeploymentBlock,
},
true // isV3
)
).to.equal(false);
// // Set oldest time older such that fill deadline buffer now exceeds the time between the end block and the oldest
// // time. Block ranges should now be valid.
// const oldestBlockTimestampOverride = endBlockTimestamps[originChainId] - fillDeadlineOverride - 1;
// assert(oldestBlockTimestampOverride > 0, "unrealistic oldest block timestamp");
// mockSpokePoolClient.setOldestBlockTimestampOverride(oldestBlockTimestampOverride);
// expect(
// await blockRangesAreInvalidForSpokeClients(
// { [originChainId]: mockSpokePoolClient as SpokePoolClient },
// blockRanges,
// chainIds,
// {
// [originChainId]: mainnetDeploymentBlock,
// },
// true // isV3
// )
// ).to.equal(false);

// Finally, reset fill deadline buffer in contracts and reset the override in the mock to test that
// the client calls from the contracts.
mockSpokePoolClient.setOldestBlockTimestampOverride(undefined);
mockSpokePoolClient.setMaxFillDeadlineOverride(undefined);
fakeSpokePool.fillDeadlineBuffer.returns(expectedTimeBetweenOldestAndEndBlockTimestamp); // This should be same
// length as time between oldest time and end block timestamp so it should be a valid block range.
expect(
await blockRangesAreInvalidForSpokeClients(
{ [originChainId]: mockSpokePoolClient as SpokePoolClient },
blockRanges,
chainIds,
{
[originChainId]: mainnetDeploymentBlock,
},
true // isV3
)
).to.equal(false);
// // Finally, reset fill deadline buffer in contracts and reset the override in the mock to test that
// // the client calls from the contracts.
// mockSpokePoolClient.setOldestBlockTimestampOverride(undefined);
// mockSpokePoolClient.setMaxFillDeadlineOverride(undefined);
// fakeSpokePool.fillDeadlineBuffer.returns(expectedTimeBetweenOldestAndEndBlockTimestamp); // This should be same
// // length as time between oldest time and end block timestamp so it should be a valid block range.
// expect(
// await blockRangesAreInvalidForSpokeClients(
// { [originChainId]: mockSpokePoolClient as SpokePoolClient },
// blockRanges,
// chainIds,
// {
// [originChainId]: mainnetDeploymentBlock,
// },
// true // isV3
// )
// ).to.equal(false);
});
});

0 comments on commit 23f63d3

Please sign in to comment.