Skip to content

Commit

Permalink
feat: add dataworker force bundle range (#912)
Browse files Browse the repository at this point in the history
* feat: add dataworker force bundle range

* docs: add documentation to example env

* improve: allow for boba

* improve: allow forced proposal range with sending

---------

Co-authored-by: Paul <[email protected]>
  • Loading branch information
james-a-morris and pxrl authored Sep 19, 2023
1 parent 3b4c101 commit e6e245c
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -252,3 +252,9 @@ RELAYER_TOKENS='["0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", "0xA0b86991c6218b
# Note: This logic ONLY works if `SEND_PROPOSALS` is set to false.
#FORCE_PROPOSAL=false

# This variable can be used to simulate a bundle range that a proposal will be created for.
# This is useful for testing the disputer and proposer logic. The format is:
# [number, number][] where the two numbers are the start and end bundle ranges and the array
# represents the bundle ranges that will be proposed per the chain id indices.
# Note: This logic ONLY works if `SEND_PROPOSALS` and `SEND_DISPUTES` are BOTH set to false.
# FORCE_PROPOSAL_BUNDLE_RANGE = [[1, 2], [1, 3], ...]
9 changes: 7 additions & 2 deletions src/dataworker/Dataworker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ export class Dataworker {
readonly blockRangeEndBlockBuffer: { [chainId: number]: number } = {},
readonly spokeRootsLookbackCount = 0,
readonly bufferToPropose = 0,
readonly forceProposal = false
readonly forceProposal = false,
readonly forceBundleRange?: [number, number][]
) {
if (
maxRefundCountOverride !== undefined ||
Expand Down Expand Up @@ -344,7 +345,11 @@ export class Dataworker {
// For now, we assume that if one blockchain fails to return data, then this entire function will fail. This is a
// safe strategy but could lead to new roots failing to be proposed until ALL networks are healthy.

const blockRangesForProposal = this._getNextProposalBlockRanges(spokePoolClients, earliestBlocksInSpokePoolClients);
// If we are forcing a bundle range, then we should use that instead of the next proposal block ranges.
const blockRangesForProposal = isDefined(this.forceBundleRange)
? this.forceBundleRange
: this._getNextProposalBlockRanges(spokePoolClients, earliestBlocksInSpokePoolClients);

if (!blockRangesForProposal) {
return;
}
Expand Down
30 changes: 30 additions & 0 deletions src/dataworker/DataworkerConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ export class DataworkerConfig extends CommonConfig {
// a bundle. This is useful for testing the disputer logic.
readonly forcePropose: boolean;

// This variable can be used to simulate a bundle range that a proposal will be created for.
// This is useful for testing the disputer and proposer logic. The format is:
// [number, number][] where the two numbers are the start and end bundle ranges and the array
// represents the bundle ranges that will be proposed per the chain id indices.
readonly forceProposalBundleRange?: [number, number][];

// These variables can be toggled to choose whether the bot will submit transactions created
// by each function. For example, setting `sendingDisputesEnabled=false` but `disputerEnabled=true`
// means that the disputer logic will be run but won't send disputes on-chain.
Expand Down Expand Up @@ -51,6 +57,7 @@ export class DataworkerConfig extends CommonConfig {
DATAWORKER_FAST_LOOKBACK_COUNT,
DATAWORKER_FAST_START_BUNDLE,
FORCE_PROPOSAL,
FORCE_PROPOSAL_BUNDLE_RANGE,
} = env;
super(env);

Expand Down Expand Up @@ -91,6 +98,29 @@ export class DataworkerConfig extends CommonConfig {

this.forcePropose = FORCE_PROPOSAL === "true";

// If FORCE_PROPOSAL_BUNDLE_RANGE is set, then we want to force a specific bundle range.
if (FORCE_PROPOSAL_BUNDLE_RANGE) {
// The format is [number, number][] where the two numbers are the start and end bundle ranges and the array
// represents the bundle ranges that will be proposed per the chain id indices.
this.forceProposalBundleRange = JSON.parse(FORCE_PROPOSAL_BUNDLE_RANGE);
// We need to ensure that the bundle ranges are valid. A valid bundle range
// is an array of [start, end] where both start and end are numeric and
// positive whole numbers and start < end.
this.forceProposalBundleRange.forEach((bundleRange, index) => {
assert(Array.isArray(bundleRange), `forceProposalBundleRange[${index}] is not an array`);
assert(bundleRange.length === 2, `forceProposalBundleRange[${index}] does not have length 2`);
const [start, end] = bundleRange;
assert(typeof start === "number", `forceProposalBundleRange[${index}][start] is not a number`);
assert(typeof end === "number", `forceProposalBundleRange[${index}][end] is not a number`);
assert(start > 0, `forceProposalBundleRange[${index}][start] is not positive`);
assert(end > 0, `forceProposalBundleRange[${index}][end] is not positive`);
assert(start <= end, `forceProposalBundleRange[${index}][start] >= forceProposalBundleRange[${index}][end]`);
});
} else {
// If FORCE_PROPOSAL_BUNDLE_RANGE is not set, then we don't want to force a specific bundle range.
this.forceProposalBundleRange = undefined;
}

// We NEVER want to force propose if the proposer is enabled.
if (this.sendingProposalsEnabled) {
assert(!this.forcePropose, "Cannot force propose if sending proposals is enabled");
Expand Down
3 changes: 2 additions & 1 deletion src/dataworker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ export async function createDataworker(
config.blockRangeEndBlockBuffer,
config.spokeRootsLookbackCount,
config.bufferToPropose,
config.forcePropose
config.forcePropose,
config.forceProposalBundleRange
);

return {
Expand Down

0 comments on commit e6e245c

Please sign in to comment.