-
Notifications
You must be signed in to change notification settings - Fork 270
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allows sequencers to register themselves on the rollup contract, and they take turns to submit blocks. If there are no sequeners registered, it's a free-for-all.
- Loading branch information
1 parent
14e0c1d
commit 19c2a97
Showing
8 changed files
with
237 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import { createEthereumChain } from '@aztec/ethereum'; | ||
import { type DebugLogger, type LogFn } from '@aztec/foundation/log'; | ||
import { RollupAbi } from '@aztec/l1-artifacts'; | ||
|
||
import { createPublicClient, createWalletClient, getContract, http } from 'viem'; | ||
import { mnemonicToAccount } from 'viem/accounts'; | ||
|
||
import { createCompatibleClient } from '../client.js'; | ||
|
||
export async function sequencers(opts: { | ||
command: 'list' | 'add' | 'remove' | 'who-next'; | ||
who?: string; | ||
mnemonic?: string; | ||
rpcUrl: string; | ||
l1RpcUrl: string; | ||
apiKey: string; | ||
blockNumber?: number; | ||
log: LogFn; | ||
debugLogger: DebugLogger; | ||
}) { | ||
const { | ||
blockNumber: maybeBlockNumber, | ||
command, | ||
who: maybeWho, | ||
mnemonic, | ||
rpcUrl, | ||
l1RpcUrl, | ||
apiKey, | ||
log, | ||
debugLogger, | ||
} = opts; | ||
const client = await createCompatibleClient(rpcUrl, debugLogger); | ||
const { l1ContractAddresses } = await client.getNodeInfo(); | ||
|
||
const chain = createEthereumChain(l1RpcUrl, apiKey); | ||
const publicClient = createPublicClient({ chain: chain.chainInfo, transport: http(chain.rpcUrl) }); | ||
|
||
const walletClient = mnemonic | ||
? createWalletClient({ | ||
account: mnemonicToAccount(mnemonic), | ||
chain: chain.chainInfo, | ||
transport: http(chain.rpcUrl), | ||
}) | ||
: undefined; | ||
|
||
const rollup = getContract({ | ||
address: l1ContractAddresses.rollupAddress.toString(), | ||
abi: RollupAbi, | ||
client: publicClient, | ||
}); | ||
|
||
const writeableRollup = walletClient | ||
? getContract({ | ||
address: l1ContractAddresses.rollupAddress.toString(), | ||
abi: RollupAbi, | ||
client: walletClient, | ||
}) | ||
: undefined; | ||
|
||
const who = (maybeWho as `0x{string}`) ?? walletClient?.account.address.toString(); | ||
|
||
if (command === 'list') { | ||
const sequencers = await rollup.read.getSequencers(); | ||
if (sequencers.length === 0) { | ||
log(`No sequencers registered on rollup`); | ||
} else { | ||
log(`Registered sequencers on rollup:`); | ||
for (const sequencer of sequencers) { | ||
log(' ' + sequencer.toString()); | ||
} | ||
} | ||
} else if (command === 'add') { | ||
if (!who || !writeableRollup) { | ||
throw new Error(`Missing sequencer address`); | ||
} | ||
log(`Adding ${who} as sequencer`); | ||
const hash = await writeableRollup.write.addSequencer([who]); | ||
await publicClient.waitForTransactionReceipt({ hash }); | ||
log(`Added in tx ${hash}`); | ||
} else if (command === 'remove') { | ||
if (!who || !writeableRollup) { | ||
throw new Error(`Missing sequencer address`); | ||
} | ||
log(`Removing ${who} as sequencer`); | ||
const hash = await writeableRollup.write.removeSequencer([who]); | ||
await publicClient.waitForTransactionReceipt({ hash }); | ||
log(`Removed in tx ${hash}`); | ||
} else if (command === 'who-next') { | ||
const blockNumber = maybeBlockNumber ?? (await client.getBlockNumber()) + 1; | ||
const next = await rollup.read.whoseTurnIsIt([BigInt(blockNumber)]); | ||
log(`Next sequencer expected to build ${blockNumber} is ${next}`); | ||
} else { | ||
throw new Error(`Unknown command ${command}`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters