Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

algod: Allow timestamp offsets in dev mode #5296

Merged
merged 39 commits into from
Apr 20, 2023

Conversation

algochoi
Copy link
Contributor

@algochoi algochoi commented Apr 11, 2023

Summary

This PR allows users to change timestamps in block headers in dev mode. Users can use the v2/devmode/blocks/offset algod endpoint to set a timestamp delta between blocks. There is also a small dev-mode-only change that sets the block seed in the header to the block hash (previously, the seed was not populated in dev mode).

When we are not in dev mode, the handlers return a 404 error by checking the genesis config. Optionally, we can consider adding another handler-level config like EnableDeveloperAPI to ensure that the node can accept dev-mode related APIs.

Closes #3192 #4423

Test Plan

Added dev mode handler tests and tested on sandbox using dev mode and non dev mode.

Tested that timestamp/seed related TEAL opcodes work properly in dev mode (TEAL script here):

global LatestTimestamp
block BlkSeed
block BlkTimeStamp
txn FirstValidTime

Currently can curl offset endpoint to set timestamp offsets in dev mode:

# Sandbox: Set timestamp offsets to 1000s 
curl -i -X POST -H "X-Algo-API-Token:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" localhost:4001/v2/devnet/blocks/offset/1000

@algochoi
Copy link
Contributor Author

algochoi commented Apr 12, 2023

@jannotti I set the block seed to be the previous block's hash in dev mode as part of #4423:

// Only in dev mode
BlockHeader: BlockHeader{
	// stuff
	Seed:         committee.Seed(prev.Hash()),
},

diff: https://github.com/algorand/go-algorand/pull/5296/files#diff-da02af82e8255801f2338dd5681ec7e0ae05caf0e1a4c8ae4b34fce4b7c3613eR564

Copy link
Contributor

@tzaffi tzaffi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've read a portion of the PR and am planning to read more. The approach looks solid. I left some questions and a few nit's regarding comments and documentation.

daemon/algod/api/algod.oas2.json Outdated Show resolved Hide resolved
daemon/algod/api/algod.oas2.json Outdated Show resolved Hide resolved
daemon/algod/api/algod.oas3.yml Outdated Show resolved Hide resolved
daemon/algod/api/server/v2/handlers.go Outdated Show resolved Hide resolved
node/follower_node.go Show resolved Hide resolved
data/pools/transactionPool.go Outdated Show resolved Hide resolved
data/bookkeeping/block.go Outdated Show resolved Hide resolved
data/bookkeeping/block.go Outdated Show resolved Hide resolved
data/bookkeeping/block.go Outdated Show resolved Hide resolved
shiqizng
shiqizng previously approved these changes Apr 19, 2023
@algochoi algochoi requested a review from winder April 19, 2023 18:24
winder
winder previously approved these changes Apr 19, 2023
winder
winder previously approved these changes Apr 19, 2023
@@ -482,7 +482,7 @@ func (node *AlgorandFullNode) writeDevmodeBlock() (err error) {

// Set block timestamp based on offset, if set.
// Make sure block timestamp is not greater than MaxInt64.
if node.timestampOffset != nil && prev.TimeStamp+*node.timestampOffset < math.MaxInt64 {
if node.timestampOffset != nil && *node.timestampOffset < math.MaxInt64-prev.TimeStamp {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it can be <= here.

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

Successfully merging this pull request may close these issues.

SPIKE Add ability to advance time when network is in devmode
7 participants