Skip to content

Commit

Permalink
fix!: close epochs based on block numbers
Browse files Browse the repository at this point in the history
- Fixes the ClaimMismatch bug on v.1x.
- BREAKING CHANGE: replaces the CARTESI_EPOCH_DURATION environment
  variable with CARTESI_EPOCH_LENGTH_IN_BLOCKS.
  • Loading branch information
renan061 committed Jun 21, 2024
1 parent a04487a commit 4172eeb
Show file tree
Hide file tree
Showing 17 changed files with 830 additions and 645 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Added Rollups end-to-end test using Echo Dapp

### Fixed

- Fixed a bug that caused a `authority_claimer::ClaimMismatch` error when reprocessing inputs after a reboot.

### Changed

- Changed the dispatcher to close epochs based on block numbers instead of block timestamps.
- **BREAKING**: replaced the environment variable `CARTESI_EPOCH_DURATION` with `CARTESI_EPOCH_LENGTH_IN_BLOCKS` to match the new epoch algorithm, and set its default value to 7200 (1 day worth of blocks, in average, considering one block is mined every 12 seconds).
- **BREAKING**: replaced the internal environment variable `RD_EPOCH_DURATION` with `RD_EPOCH_LENGTH_IN_BLOCKS` to match the new epoch algorithm, and also set its default value to 7200.

## [1.4.0] 2024-04-09

### Added
Expand Down
2 changes: 1 addition & 1 deletion build/compose-devnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ services:
CARTESI_CONTRACTS_AUTHORITY_ADDRESS: "0x58c93F83fb3304730C95aad2E360cdb88b782010"
CARTESI_CONTRACTS_INPUT_BOX_ADDRESS: "0x59b22D57D4f067708AB0c00552767405926dc768"
CARTESI_CONTRACTS_INPUT_BOX_DEPLOYMENT_BLOCK_NUMBER: "20"
CARTESI_EPOCH_DURATION: "120"
CARTESI_EPOCH_LENGTH_IN_BLOCKS: "120"
CARTESI_FEATURE_DISABLE_MACHINE_HASH_CHECK: "true"
CARTESI_AUTH_KIND: "mnemonic"
CARTESI_AUTH_MNEMONIC: "test test test test test test test test test test test junk"
8 changes: 4 additions & 4 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,14 @@ for more information.
* **Type:** `string`
* **Default:** `""`

## `CARTESI_EPOCH_DURATION`
## `CARTESI_EPOCH_LENGTH_IN_BLOCKS`

Duration of a rollups epoch in seconds.
Length of a rollups epoch in blocks.

At the end of each epoch, the node will send claims to the blockchain.

* **Type:** `Duration`
* **Default:** `"86400"`
* **Type:** `uint64`
* **Default:** `"7200"`

## `CARTESI_SNAPSHOT_DIR`

Expand Down
4 changes: 2 additions & 2 deletions internal/node/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
type NodeConfig struct {
LogLevel LogLevel
LogPretty bool
RollupsEpochDuration Duration
RollupsEpochLengthInBlocks uint64
BlockchainID uint64
BlockchainHttpEndpoint Redacted[string]
BlockchainWsEndpoint Redacted[string]
Expand Down Expand Up @@ -75,7 +75,7 @@ func FromEnv() NodeConfig {
var config NodeConfig
config.LogLevel = getLogLevel()
config.LogPretty = getLogPretty()
config.RollupsEpochDuration = getEpochDuration()
config.RollupsEpochLengthInBlocks = getEpochLengthInBlocks()
config.BlockchainID = getBlockchainId()
config.BlockchainHttpEndpoint = Redacted[string]{getBlockchainHttpEndpoint()}
config.BlockchainWsEndpoint = Redacted[string]{getBlockchainWsEndpoint()}
Expand Down
8 changes: 4 additions & 4 deletions internal/node/config/generate/Config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ the snapshot matches the hash in the Application contract."""
# Rollups
#

[rollups.CARTESI_EPOCH_DURATION]
default = "86400" # 1 day in seconds
go-type = "Duration"
[rollups.CARTESI_EPOCH_LENGTH_IN_BLOCKS]
default = "7200" # 1 day (average) in blocks (considering one block is mined every 12 seconds)
go-type = "uint64"
description = """
Duration of a rollups epoch in seconds.
Length of a rollups epoch in blocks.
At the end of each epoch, the node will send claims to the blockchain."""

Expand Down
10 changes: 5 additions & 5 deletions internal/node/config/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions internal/node/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,7 @@ func newDispatcher(c config.NodeConfig, workDir string) services.CommandService
s.Env = append(s.Env, fmt.Sprintf("HISTORY_ADDRESS=%v", c.ContractsHistoryAddress))
s.Env = append(s.Env, fmt.Sprintf("AUTHORITY_ADDRESS=%v", c.ContractsAuthorityAddress))
s.Env = append(s.Env, fmt.Sprintf("INPUT_BOX_ADDRESS=%v", c.ContractsInputBoxAddress))
s.Env = append(s.Env, fmt.Sprintf("RD_EPOCH_DURATION=%v",
int(c.RollupsEpochDuration.Seconds())))
s.Env = append(s.Env, fmt.Sprintf("RD_EPOCH_LENGTH_IN_BLOCKS=%v", c.RollupsEpochLengthInBlocks))
s.Env = append(s.Env, fmt.Sprintf("CHAIN_ID=%v", c.BlockchainID))
s.Env = append(s.Env, fmt.Sprintf("DISPATCHER_HTTP_SERVER_PORT=%v",
getPort(c, portOffsetDispatcher)))
Expand Down
10 changes: 5 additions & 5 deletions offchain/dispatcher/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ pub struct DispatcherEnvCLIConfig {
#[command(flatten)]
pub blockchain_config: BlockchainCLIConfig,

/// Duration of rollups epoch in seconds, for which dispatcher will make claims.
#[arg(long, env, default_value = "604800")]
pub rd_epoch_duration: u64,
/// Duration of rollups epoch in blocks, for which dispatcher will make claims.
#[arg(long, env, default_value = "7200")]
pub rd_epoch_length_in_blocks: u64,

/// Chain ID
#[arg(long, env)]
Expand All @@ -46,7 +46,7 @@ pub struct DispatcherConfig {
pub log_config: LogConfig,
pub blockchain_config: BlockchainConfig,

pub epoch_duration: u64,
pub epoch_length_in_blocks: u64,
pub chain_id: u64,
}

Expand Down Expand Up @@ -86,7 +86,7 @@ impl Config {
broker_config,
log_config,
blockchain_config,
epoch_duration: dispatcher_config.rd_epoch_duration,
epoch_length_in_blocks: dispatcher_config.rd_epoch_length_in_blocks,
chain_id: dispatcher_config.chain_id,
};

Expand Down
Loading

0 comments on commit 4172eeb

Please sign in to comment.