Skip to content

Instantly share code, notes, and snippets.

@algochoi
Last active April 4, 2023 04:06
Show Gist options
  • Save algochoi/1de69dd2f5c9dd7ac603d07e7b98c37f to your computer and use it in GitHub Desktop.
Save algochoi/1de69dd2f5c9dd7ac603d07e7b98c37f to your computer and use it in GitHub Desktop.
Dev mode node notes

Developer node

Some notes on dev mode

Configurations

Dev mode is a boolean that can be set in the genesis file. This is read into the Genesis struct in data/bookkeeping/genesis.go. This is also recorded to the full node config AlgorandFullNode.

Node functions

When in dev mode, the node factory MakeFull in node/node.go will initialize a frozen clock for the dev mode node. The node will also create empty voting keys (don't need agreement) and turn off broadcasting txns to the network.

Creating a block

In dev mode, each transaction group is written to a block immediately.

  • In BroadcastSignedTxGroup, instead of broadcasting, we write to the block. This is only callable through the v2/transactions/send algod API.
  • There is some pre-processing done in broadcastSignedTxGroup to remember the tx group in the pool. Then it writes the block in writeDevModeBlock/AssembleDevModeBlock.
  • In AssembleDevModeBlock, it calls pool.recomputeBlockEvaluator(nil, 0) which pregenerates the block, and calls AssembleBlock.

There is a BroadcastInternalSignedTxGroup that also exits early for a dev mode block, that is called in stateproof/builder.go.

Setting custom values in the block header

bookkeeping.Block has a BlockHeader struct that can be modified. But ValidatedBlock cannot edit the contents of the block header.

Design thoughts

node does not have direct write access to the block header. We can change the timestamp in pools.recomputeBlockEvaluator which is called in AssembleDevModeBlock. In order to do so, we need to set the timestamp offset in the TransactionPool object as well, either by a direct setter or passing in params through AssembleDevModeBlock. We may also want to pass in a "devmodeConfig" instead, if we want to change the block header in dev mode in more than one ways (e.g. set a block seed).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment