From 0ae9fc2eec7401837ccd15e50c2701b3cfb04828 Mon Sep 17 00:00:00 2001 From: Hubert Bugaj Date: Mon, 13 May 2024 11:35:21 +0200 Subject: [PATCH] feat: impl `Filecoin.StateGetNetworkParams` --- CHANGELOG.md | 3 + src/networks/butterflynet/mod.rs | 95 ++++---- src/networks/calibnet/mod.rs | 275 ++++++------------------ src/networks/devnet/mod.rs | 230 +++++++++++--------- src/networks/mainnet/mod.rs | 240 +++++---------------- src/networks/mod.rs | 80 ++++++- src/rpc/methods/state.rs | 162 ++++++++++++++ src/shim/version.rs | 1 + src/state_manager/circulating_supply.rs | 2 +- src/tool/subcommands/api_cmd.rs | 1 + 10 files changed, 532 insertions(+), 557 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e19731af0a1..dccc4a72e879 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -80,6 +80,9 @@ - [#4255](https://github.com/ChainSafe/forest/pull/4255) Add support for the `Filecoin.MinerCreateBlock` RPC method. +- [#4315](https://github.com/ChainSafe/forest/pull/4315) Add support for the + `Filecoin.StateGetNetworkParams` RPC method. + ### Changed - [#4170](https://github.com/ChainSafe/forest/pull/4170) Change the default diff --git a/src/networks/butterflynet/mod.rs b/src/networks/butterflynet/mod.rs index 27cc34b6e852..c7cbd3e5f628 100644 --- a/src/networks/butterflynet/mod.rs +++ b/src/networks/butterflynet/mod.rs @@ -8,7 +8,7 @@ use once_cell::sync::Lazy; use std::str::FromStr; use url::Url; -use crate::{db::SettingsStore, shim::version::NetworkVersion, utils::net::http_get}; +use crate::{db::SettingsStore, make_height, shim::version::NetworkVersion, utils::net::http_get}; use super::{ drand::{DRAND_MAINNET, DRAND_QUICKNET}, @@ -66,71 +66,52 @@ pub static DEFAULT_BOOTSTRAP: Lazy> = // https://github.com/ethereum-lists/chains/blob/4731f6713c6fc2bf2ae727388642954a6545b3a9/_data/chains/eip155-314159.json pub const ETH_CHAIN_ID: u64 = 3141592; +pub const BREEZE_GAS_TAMPING_DURATION: i64 = 120; + /// Height epochs. pub static HEIGHT_INFOS: Lazy> = Lazy::new(|| { HashMap::from_iter([ - ( - Height::Breeze, - HeightInfo { - epoch: -50, - bundle: None, - }, - ), - ( - Height::Smoke, - HeightInfo { - epoch: -2, - bundle: None, - }, - ), - ( - Height::Ignition, - HeightInfo { - epoch: -3, - bundle: None, - }, - ), - ( - Height::ActorsV2, - HeightInfo { - epoch: -3, - bundle: None, - }, + make_height!(Breeze, -50), + make_height!(Smoke, -2), + make_height!(Ignition, -3), + make_height!(Refuel, -4), + make_height!(Assembly, -5), + make_height!(Tape, -6), + make_height!(Liftoff, -7), + make_height!(Kumquat, -8), + make_height!(Calico, -9), + make_height!(Persian, -10), + make_height!(Claus, -11), + make_height!(Orange, -12), + make_height!(Trust, -13), + make_height!(Norwegian, -14), + make_height!(Turbo, -15), + make_height!(Hyperdrive, -16), + make_height!(Chocolate, -17), + make_height!(OhSnap, -18), + make_height!(Skyr, -19), + make_height!(Shark, -20), + make_height!(Hygge, -21), + make_height!(Lightning, -22), + make_height!(Thunder, -23), + make_height!( + Watermelon, + -1, + "bafy2bzacectxvbk77ntedhztd6sszp2btrtvsmy7lp2ypnrk6yl74zb34t2cq" ), - ( - Height::Liftoff, - HeightInfo { - epoch: -6, - bundle: None, - }, + make_height!( + Dragon, + 480, + "bafy2bzacec75zk7ufzwx6tg5avls5fxdjx5asaqmd2bfqdvkqrkzoxgyflosu" ), ( - Height::Calico, + Height::Phoenix, HeightInfo { - epoch: -9, + epoch: 600, bundle: None, }, ), - ( - Height::Watermelon, - HeightInfo { - epoch: -1, - bundle: Some( - Cid::try_from("bafy2bzacectxvbk77ntedhztd6sszp2btrtvsmy7lp2ypnrk6yl74zb34t2cq") - .unwrap(), - ), - }, - ), - ( - Height::Dragon, - HeightInfo { - epoch: 480, - bundle: Some( - Cid::try_from("bafy2bzacec75zk7ufzwx6tg5avls5fxdjx5asaqmd2bfqdvkqrkzoxgyflosu") - .unwrap(), - ), - }, - ), + make_height!(Aussie, 9999999999), ]) }); @@ -142,7 +123,7 @@ pub(super) static DRAND_SCHEDULE: Lazy<[DrandPoint<'static>; 2]> = Lazy::new(|| }, DrandPoint { height: get_upgrade_height_from_env("FOREST_DRAND_QUICKNET_HEIGHT") - .unwrap_or(HEIGHT_INFOS.get(&Height::Dragon).unwrap().epoch + 120), + .unwrap_or(HEIGHT_INFOS.get(&Height::Phoenix).unwrap().epoch), config: &DRAND_QUICKNET, }, ] diff --git a/src/networks/calibnet/mod.rs b/src/networks/calibnet/mod.rs index 4365f7be5e2f..042a4dff6a04 100644 --- a/src/networks/calibnet/mod.rs +++ b/src/networks/calibnet/mod.rs @@ -7,7 +7,7 @@ use libp2p::Multiaddr; use once_cell::sync::Lazy; use std::str::FromStr; -use crate::shim::version::NetworkVersion; +use crate::{make_height, shim::version::NetworkVersion}; use super::{ drand::{DRAND_MAINNET, DRAND_QUICKNET}, @@ -36,216 +36,73 @@ const LIGHTNING_ROLLOVER_PERIOD: i64 = 3120; // https://github.com/ethereum-lists/chains/blob/4731f6713c6fc2bf2ae727388642954a6545b3a9/_data/chains/eip155-314159.json pub const ETH_CHAIN_ID: u64 = 314159; +pub const BREEZE_GAS_TAMPING_DURATION: i64 = 120; + /// Height epochs. pub static HEIGHT_INFOS: Lazy> = Lazy::new(|| { HashMap::from_iter([ - ( - Height::Breeze, - HeightInfo { - epoch: -1, - bundle: None, - }, - ), - ( - Height::Smoke, - HeightInfo { - epoch: -2, - bundle: None, - }, - ), - ( - Height::Ignition, - HeightInfo { - epoch: -3, - bundle: None, - }, - ), - ( - Height::ActorsV2, - HeightInfo { - epoch: 30, - bundle: None, - }, - ), - ( - Height::Tape, - HeightInfo { - epoch: 60, - bundle: None, - }, - ), - ( - Height::Liftoff, - HeightInfo { - epoch: -5, - bundle: None, - }, - ), - ( - Height::Kumquat, - HeightInfo { - epoch: 90, - bundle: None, - }, - ), - ( - Height::Calico, - HeightInfo { - epoch: 120, - bundle: None, - }, - ), - ( - Height::Persian, - HeightInfo { - epoch: 130, - bundle: None, - }, - ), - ( - Height::Orange, - HeightInfo { - epoch: 300, - bundle: None, - }, - ), - ( - Height::Trust, - HeightInfo { - epoch: 330, - bundle: None, - }, - ), - ( - Height::Norwegian, - HeightInfo { - epoch: 360, - bundle: None, - }, - ), - ( - Height::Turbo, - HeightInfo { - epoch: 390, - bundle: None, - }, - ), - ( - Height::Hyperdrive, - HeightInfo { - epoch: 420, - bundle: None, - }, - ), - ( - Height::Chocolate, - HeightInfo { - epoch: 450, - bundle: None, - }, - ), - ( - Height::OhSnap, - HeightInfo { - epoch: 480, - bundle: None, - }, - ), - ( - Height::Skyr, - HeightInfo { - epoch: 510, - bundle: None, - }, - ), - ( - Height::Shark, - HeightInfo { - epoch: 16_800, - bundle: Some( - Cid::try_from("bafy2bzacedbedgynklc4dgpyxippkxmba2mgtw7ecntoneclsvvl4klqwuyyy") - .unwrap(), - ), - }, - ), - ( - Height::Hygge, - HeightInfo { - epoch: 322_354, - bundle: Some( - Cid::try_from("bafy2bzaced25ta3j6ygs34roprilbtb3f6mxifyfnm7z7ndquaruxzdq3y7lo") - .unwrap(), - ), - }, - ), - ( - Height::Lightning, - HeightInfo { - epoch: LIGHTNING_EPOCH, - bundle: Some( - Cid::try_from("bafy2bzacedhuowetjy2h4cxnijz2l64h4mzpk5m256oywp4evarpono3cjhco") - .unwrap(), - ), - }, - ), - ( - Height::Thunder, - HeightInfo { - epoch: LIGHTNING_EPOCH + LIGHTNING_ROLLOVER_PERIOD, - bundle: None, - }, - ), - ( - Height::Watermelon, - HeightInfo { - epoch: 1_013_134, - bundle: Some( - Cid::try_from("bafy2bzacedrunxfqta5skb7q7x32lnp4efz2oq7fn226ffm7fu5iqs62jkmvs") - .unwrap(), - ), - }, - ), - ( - Height::WatermelonFix, - HeightInfo { - epoch: 1_070_494, - bundle: Some( - Cid::try_from("bafy2bzacebl4w5ptfvuw6746w7ev562idkbf5ppq72e6zub22435ws2rukzru") - .unwrap(), - ), - }, - ), - ( - Height::WatermelonFix2, - HeightInfo { - epoch: 1_108_174, - bundle: Some( - Cid::try_from("bafy2bzacednzb3pkrfnbfhmoqtb3bc6dgvxszpqklf3qcc7qzcage4ewzxsca") - .unwrap(), - ), - }, - ), - ( - Height::Dragon, - HeightInfo { - epoch: 1_427_974, - bundle: Some( - Cid::try_from("bafy2bzacea4firkyvt2zzdwqjrws5pyeluaesh6uaid246tommayr4337xpmi") - .unwrap(), - ), - }, - ), - ( - Height::DragonFix, - HeightInfo { - // Wed Apr 3 11:00:00 AM UTC 2024 - epoch: 1_493_854, - bundle: Some( - Cid::try_from("bafy2bzacect4ktyujrwp6mjlsitnpvuw2pbuppz6w52sfljyo4agjevzm75qs") - .unwrap(), - ), - }, - ), + make_height!(Breeze, -1), + make_height!(Smoke, -2), + make_height!(Ignition, -3), + make_height!(Refuel, -4), + make_height!(Assembly, 30), + make_height!(Tape, 60), + make_height!(Liftoff, -5), + make_height!(Kumquat, 90), + make_height!(Calico, 120), + make_height!(Persian, 240), + make_height!(Claus, 270), + make_height!(Orange, 300), + make_height!(Trust, 330), + make_height!(Norwegian, 360), + make_height!(Turbo, 390), + make_height!(Hyperdrive, 420), + make_height!(Chocolate, 450), + make_height!(OhSnap, 480), + make_height!(Skyr, 510), + make_height!( + Shark, + 16_800, + "bafy2bzacedbedgynklc4dgpyxippkxmba2mgtw7ecntoneclsvvl4klqwuyyy" + ), + make_height!( + Hygge, + 322_354, + "bafy2bzaced25ta3j6ygs34roprilbtb3f6mxifyfnm7z7ndquaruxzdq3y7lo" + ), + make_height!( + Lightning, + LIGHTNING_EPOCH, + "bafy2bzacedhuowetjy2h4cxnijz2l64h4mzpk5m256oywp4evarpono3cjhco" + ), + make_height!(Thunder, LIGHTNING_EPOCH + LIGHTNING_ROLLOVER_PERIOD), + make_height!( + Watermelon, + 1_013_134, + "bafy2bzacedrunxfqta5skb7q7x32lnp4efz2oq7fn226ffm7fu5iqs62jkmvs" + ), + make_height!( + WatermelonFix, + 1_070_494, + "bafy2bzacebl4w5ptfvuw6746w7ev562idkbf5ppq72e6zub22435ws2rukzru" + ), + make_height!( + WatermelonFix2, + 1_108_174, + "bafy2bzacednzb3pkrfnbfhmoqtb3bc6dgvxszpqklf3qcc7qzcage4ewzxsca" + ), + make_height!( + Dragon, + 1_427_974, + "bafy2bzacea4firkyvt2zzdwqjrws5pyeluaesh6uaid246tommayr4337xpmi" + ), + make_height!( + DragonFix, + 1_493_854, + "bafy2bzacect4ktyujrwp6mjlsitnpvuw2pbuppz6w52sfljyo4agjevzm75qs" + ), + make_height!(Phoenix, 1_428_094), + make_height!(Aussie, 999999999999999), ]) }); @@ -257,7 +114,7 @@ pub(super) static DRAND_SCHEDULE: Lazy<[DrandPoint<'static>; 2]> = Lazy::new(|| }, DrandPoint { height: get_upgrade_height_from_env("FOREST_DRAND_QUICKNET_HEIGHT") - .unwrap_or(HEIGHT_INFOS.get(&Height::Dragon).unwrap().epoch + 120), + .unwrap_or(HEIGHT_INFOS.get(&Height::Phoenix).unwrap().epoch), config: &DRAND_QUICKNET, }, ] diff --git a/src/networks/devnet/mod.rs b/src/networks/devnet/mod.rs index 6b84a905f9f1..3c7eda186bbc 100644 --- a/src/networks/devnet/mod.rs +++ b/src/networks/devnet/mod.rs @@ -5,7 +5,7 @@ use ahash::HashMap; use cid::Cid; use once_cell::sync::Lazy; -use crate::shim::version::NetworkVersion; +use crate::{make_height, shim::version::NetworkVersion}; use super::{ drand::{DRAND_MAINNET, DRAND_QUICKNET}, @@ -15,6 +15,8 @@ use super::{ // https://github.com/ethereum-lists/chains/blob/6b1e3ccad1cfcaae5aa1ab917960258f0ef1a6b6/_data/chains/eip155-31415926.json pub const ETH_CHAIN_ID: u64 = 31415926; +pub const BREEZE_GAS_TAMPING_DURATION: i64 = 0; + pub static GENESIS_NETWORK_VERSION: Lazy = Lazy::new(|| { if let Ok(version) = std::env::var("FOREST_GENESIS_NETWORK_VERSION") { NetworkVersion::from( @@ -32,104 +34,134 @@ pub static GENESIS_NETWORK_VERSION: Lazy = Lazy::new(|| { /// pub static HEIGHT_INFOS: Lazy> = Lazy::new(|| { HashMap::from_iter([ - ( - Height::Breeze, - HeightInfo { - epoch: get_upgrade_height_from_env("FOREST_BREEZE_HEIGHT").unwrap_or(-50), - bundle: None, - }, - ), - ( - Height::Smoke, - HeightInfo { - epoch: get_upgrade_height_from_env("FOREST_SMOKE_HEIGHT").unwrap_or(-2), - bundle: None, - }, - ), - ( - Height::Ignition, - HeightInfo { - epoch: get_upgrade_height_from_env("FOREST_IGNITION_HEIGHT").unwrap_or(-3), - bundle: None, - }, - ), - ( - Height::ActorsV2, - HeightInfo { - epoch: get_upgrade_height_from_env("FOREST_ACTORSV2_HEIGHT").unwrap_or(-3), - bundle: None, - }, - ), - ( - Height::Liftoff, - HeightInfo { - epoch: get_upgrade_height_from_env("FOREST_LIFTOFF_HEIGHT").unwrap_or(-6), - bundle: None, - }, - ), - ( - Height::Calico, - HeightInfo { - epoch: get_upgrade_height_from_env("FOREST_CALICO_HEIGHT").unwrap_or(-9), - bundle: None, - }, - ), - ( - Height::Shark, - HeightInfo { - epoch: get_upgrade_height_from_env("FOREST_SHARK_HEIGHT").unwrap_or(-20), - bundle: Some( - Cid::try_from("bafy2bzacedozk3jh2j4nobqotkbofodq4chbrabioxbfrygpldgoxs3zwgggk") - .unwrap(), - ), - }, - ), - ( - Height::Hygge, - HeightInfo { - epoch: get_upgrade_height_from_env("FOREST_HYGGE_HEIGHT").unwrap_or(-21), - bundle: Some( - Cid::try_from("bafy2bzacebzz376j5kizfck56366kdz5aut6ktqrvqbi3efa2d4l2o2m653ts") - .unwrap(), - ), - }, - ), - ( - Height::Lightning, - HeightInfo { - epoch: get_upgrade_height_from_env("FOREST_LIGHTNING_HEIGHT").unwrap_or(-22), - bundle: Some( - Cid::try_from("bafy2bzaceay35go4xbjb45km6o46e5bib3bi46panhovcbedrynzwmm3drr4i") - .unwrap(), - ), - }, - ), - ( - Height::Thunder, - HeightInfo { - epoch: get_upgrade_height_from_env("FOREST_THUNDER_HEIGHT").unwrap_or(-23), - bundle: None, - }, - ), - ( - Height::Watermelon, - HeightInfo { - epoch: get_upgrade_height_from_env("FOREST_WATERMELON_HEIGHT").unwrap_or(-1), - bundle: Some( - Cid::try_from("bafy2bzaceasjdukhhyjbegpli247vbf5h64f7uvxhhebdihuqsj2mwisdwa6o") - .unwrap(), - ), - }, - ), - ( - Height::Dragon, - HeightInfo { - epoch: get_upgrade_height_from_env("FOREST_DRAGON_HEIGHT").unwrap_or(20), - bundle: Some( - Cid::try_from("bafy2bzacecn7uxgehrqbcs462ktl2h23u23cmduy2etqj6xrd6tkkja56fna4") - .unwrap(), - ), - }, + make_height!( + Breeze, + get_upgrade_height_from_env("FOREST_BREEZE_HEIGHT").unwrap_or(-50) + ), + make_height!( + Smoke, + get_upgrade_height_from_env("FOREST_SMOKE_HEIGHT").unwrap_or(-2) + ), + make_height!( + Ignition, + get_upgrade_height_from_env("FOREST_IGNITION_HEIGHT").unwrap_or(-3) + ), + make_height!( + Refuel, + get_upgrade_height_from_env("FOREST_REFUEL_HEIGHT").unwrap_or(-4) + ), + make_height!( + Assembly, + get_upgrade_height_from_env("FOREST_ASSEMBLY_HEIGHT").unwrap_or(-5) + ), + make_height!( + Tape, + get_upgrade_height_from_env("FOREST_TAPE_HEIGHT").unwrap_or(-6) + ), + make_height!( + Liftoff, + get_upgrade_height_from_env("FOREST_LIFTOFF_HEIGHT").unwrap_or(-7) + ), + make_height!( + Kumquat, + get_upgrade_height_from_env("FOREST_KUMQUAT_HEIGHT").unwrap_or(-8) + ), + make_height!( + Calico, + get_upgrade_height_from_env("FOREST_CALICO_HEIGHT").unwrap_or(-9) + ), + make_height!( + Persian, + get_upgrade_height_from_env("FOREST_PERSIAN_HEIGHT").unwrap_or(-10) + ), + make_height!( + Claus, + get_upgrade_height_from_env("FOREST_CLAUS_HEIGHT").unwrap_or(-11) + ), + make_height!( + Orange, + get_upgrade_height_from_env("FOREST_ORANGE_HEIGHT").unwrap_or(-12) + ), + make_height!( + Trust, + get_upgrade_height_from_env("FOREST_TRUST_HEIGHT").unwrap_or(-13) + ), + make_height!( + Norwegian, + get_upgrade_height_from_env("FOREST_NORWEGIAN_HEIGHT").unwrap_or(-14) + ), + make_height!( + Turbo, + get_upgrade_height_from_env("FOREST_TURBO_HEIGHT").unwrap_or(-15) + ), + make_height!( + Hyperdrive, + get_upgrade_height_from_env("FOREST_HYPERDRIVE_HEIGHT").unwrap_or(-16) + ), + make_height!( + Chocolate, + get_upgrade_height_from_env("FOREST_CHOCOLATE_HEIGHT").unwrap_or(-17) + ), + make_height!( + OhSnap, + get_upgrade_height_from_env("FOREST_OHSNAP_HEIGHT").unwrap_or(-18) + ), + make_height!( + Skyr, + get_upgrade_height_from_env("FOREST_SKYR_HEIGHT").unwrap_or(-19) + ), + make_height!( + Shark, + get_upgrade_height_from_env("FOREST_SHARK_HEIGHT").unwrap_or(-20) + ), + make_height!( + Hygge, + get_upgrade_height_from_env("FOREST_HYGGE_HEIGHT").unwrap_or(-21) + ), + make_height!( + Lightning, + get_upgrade_height_from_env("FOREST_LIGHTNING_HEIGHT").unwrap_or(-22) + ), + make_height!( + Thunder, + get_upgrade_height_from_env("FOREST_THUNDER_HEIGHT").unwrap_or(-23) + ), + make_height!( + Shark, + get_upgrade_height_from_env("FOREST_SHARK_HEIGHT").unwrap_or(-24), + "bafy2bzacedozk3jh2j4nobqotkbofodq4chbrabioxbfrygpldgoxs3zwgggk" + ), + make_height!( + Hygge, + get_upgrade_height_from_env("FOREST_HYGGE_HEIGHT").unwrap_or(-25), + "bafy2bzacebzz376j5kizfck56366kdz5aut6ktqrvqbi3efa2d4l2o2m653ts" + ), + make_height!( + Lightning, + get_upgrade_height_from_env("FOREST_LIGHTNING_HEIGHT_HEIGHT").unwrap_or(-26), + "bafy2bzaceay35go4xbjb45km6o46e5bib3bi46panhovcbedrynzwmm3drr4i" + ), + make_height!( + Thunder, + get_upgrade_height_from_env("FOREST_THUNDER_HEIGHT").unwrap_or(-27) + ), + make_height!( + Watermelon, + get_upgrade_height_from_env("FOREST_WATERMELON_HEIGHT").unwrap_or(-1), + "bafy2bzaceasjdukhhyjbegpli247vbf5h64f7uvxhhebdihuqsj2mwisdwa6o" + ), + make_height!( + Dragon, + get_upgrade_height_from_env("FOREST_DRAGON_HEIGHT").unwrap_or(20), + "bafy2bzacecn7uxgehrqbcs462ktl2h23u23cmduy2etqj6xrd6tkkja56fna4" + ), + make_height!( + Phoenix, + get_upgrade_height_from_env("FOREST_DRAND_QUICKNET_HEIGHT").unwrap_or(i64::MAX) + ), + make_height!( + Aussie, + get_upgrade_height_from_env("FOREST_AUSSIE_HEIGHT").unwrap_or(9999999999) ), ]) }); diff --git a/src/networks/mainnet/mod.rs b/src/networks/mainnet/mod.rs index 4b5502a3ac7d..af5f9eeea491 100644 --- a/src/networks/mainnet/mod.rs +++ b/src/networks/mainnet/mod.rs @@ -1,7 +1,10 @@ // Copyright 2019-2024 ChainSafe Systems // SPDX-License-Identifier: Apache-2.0, MIT -use crate::shim::{clock::ChainEpoch, version::NetworkVersion}; +use crate::{ + make_height, + shim::{clock::ChainEpoch, version::NetworkVersion}, +}; use ahash::HashMap; use cid::Cid; use libp2p::Multiaddr; @@ -34,186 +37,59 @@ const LIGHTNING_ROLLOVER_PERIOD: i64 = 2880 * 21; // https://github.com/ethereum-lists/chains/blob/4731f6713c6fc2bf2ae727388642954a6545b3a9/_data/chains/eip155-314.json pub const ETH_CHAIN_ID: u64 = 314; +pub const BREEZE_GAS_TAMPING_DURATION: i64 = 120; + /// Height epochs. pub static HEIGHT_INFOS: Lazy> = Lazy::new(|| { HashMap::from_iter([ - ( - Height::Breeze, - HeightInfo { - epoch: 41_280, - bundle: None, - }, - ), - ( - Height::Smoke, - HeightInfo { - epoch: SMOKE_HEIGHT, - bundle: None, - }, - ), - ( - Height::Ignition, - HeightInfo { - epoch: 94_000, - bundle: None, - }, - ), - ( - Height::ActorsV2, - HeightInfo { - epoch: 138_720, - bundle: None, - }, - ), - ( - Height::Tape, - HeightInfo { - epoch: 140_760, - bundle: None, - }, - ), - ( - Height::Liftoff, - HeightInfo { - epoch: 148_888, - bundle: None, - }, - ), - ( - Height::Kumquat, - HeightInfo { - epoch: 170_000, - bundle: None, - }, - ), - ( - Height::Calico, - HeightInfo { - epoch: 265_200, - bundle: None, - }, - ), - ( - Height::Persian, - HeightInfo { - epoch: 272_400, - bundle: None, - }, - ), - ( - Height::Orange, - HeightInfo { - epoch: 336_458, - bundle: None, - }, - ), - ( - Height::Trust, - HeightInfo { - epoch: 550_321, - bundle: None, - }, - ), - ( - Height::Norwegian, - HeightInfo { - epoch: 665_280, - bundle: None, - }, - ), - ( - Height::Turbo, - HeightInfo { - epoch: 712_320, - bundle: None, - }, - ), - ( - Height::Hyperdrive, - HeightInfo { - epoch: 892_800, - bundle: None, - }, - ), - ( - Height::Chocolate, - HeightInfo { - epoch: 1_231_620, - bundle: None, - }, - ), - ( - Height::OhSnap, - HeightInfo { - epoch: 1_594_680, - bundle: None, - }, - ), - ( - Height::Skyr, - HeightInfo { - epoch: 1_960_320, - bundle: None, - }, - ), - ( - Height::Shark, - HeightInfo { - epoch: 2_383_680, - bundle: Some( - Cid::try_from("bafy2bzaceb6j6666h36xnhksu3ww4kxb6e25niayfgkdnifaqi6m6ooc66i6i") - .unwrap(), - ), - }, - ), - ( - Height::Hygge, - HeightInfo { - epoch: 2_683_348, - bundle: Some( - Cid::try_from("bafy2bzacecsuyf7mmvrhkx2evng5gnz5canlnz2fdlzu2lvcgptiq2pzuovos") - .unwrap(), - ), - }, - ), - ( - Height::Lightning, - HeightInfo { - epoch: 2_809_800, - bundle: Some( - Cid::try_from("bafy2bzacecnhaiwcrpyjvzl4uv4q3jzoif26okl3m66q3cijp3dfwlcxwztwo") - .unwrap(), - ), - }, - ), - ( - Height::Thunder, - HeightInfo { - epoch: 2_809_800 + LIGHTNING_ROLLOVER_PERIOD, - bundle: None, - }, - ), - ( - Height::Watermelon, - HeightInfo { - epoch: 3_469_380, - bundle: Some( - Cid::try_from("bafy2bzaceapkgfggvxyllnmuogtwasmsv5qi2qzhc2aybockd6kag2g5lzaio") - .unwrap(), - ), - }, - ), - ( - Height::Dragon, - HeightInfo { - // Thu Apr 24 02:00:00 PM UTC 2024 - epoch: 3_855_360, - bundle: Some( - Cid::try_from("bafy2bzacecdhvfmtirtojwhw2tyciu4jkbpsbk5g53oe24br27oy62sn4dc4e") - .unwrap(), - ), - }, - ), + make_height!(Breeze, 41_280), + make_height!(Smoke, SMOKE_HEIGHT), + make_height!(Ignition, 94_000), + make_height!(Refuel, 130_800), + make_height!(Assembly, 138_720), + make_height!(Tape, 140_760), + make_height!(Liftoff, 148_888), + make_height!(Kumquat, 170_000), + make_height!(Calico, 265_200), + make_height!(Persian, 272_400), + make_height!(Orange, 336_458), + make_height!(Claus, 343_200), + make_height!(Trust, 550_321), + make_height!(Norwegian, 665_280), + make_height!(Turbo, 712_320), + make_height!(Hyperdrive, 892_800), + make_height!(Chocolate, 1_231_620), + make_height!(OhSnap, 1_594_680), + make_height!(Skyr, 1_960_320), + make_height!( + Shark, + 2_383_680, + "bafy2bzaceb6j6666h36xnhksu3ww4kxb6e25niayfgkdnifaqi6m6ooc66i6i" + ), + make_height!( + Hygge, + 2_683_348, + "bafy2bzacecsuyf7mmvrhkx2evng5gnz5canlnz2fdlzu2lvcgptiq2pzuovos" + ), + make_height!( + Lightning, + 2_809_800, + "bafy2bzacecnhaiwcrpyjvzl4uv4q3jzoif26okl3m66q3cijp3dfwlcxwztwo" + ), + make_height!(Thunder, 2_809_800 + LIGHTNING_ROLLOVER_PERIOD), + make_height!( + Watermelon, + 3_469_380, + "bafy2bzaceapkgfggvxyllnmuogtwasmsv5qi2qzhc2aybockd6kag2g5lzaio" + ), + // Thu Apr 24 02:00:00 PM UTC 2024 + make_height!( + Dragon, + 3_855_360, + "bafy2bzacecdhvfmtirtojwhw2tyciu4jkbpsbk5g53oe24br27oy62sn4dc4e" + ), + make_height!(Phoenix, 3_855_480), + make_height!(Aussie, 9999999999), ]) }); @@ -228,12 +104,10 @@ pub(super) static DRAND_SCHEDULE: Lazy<[DrandPoint<'static>; 3]> = Lazy::new(|| config: &DRAND_MAINNET, }, DrandPoint { - // 2024-04-11T15:00:00Z - 120 epochs after the Dragon upgrade height: HEIGHT_INFOS - .get(&Height::Dragon) - .expect("Dragon height must be defined") - .epoch - + 120, + .get(&Height::Phoenix) + .expect("Phoenix height must be defined") + .epoch, config: &DRAND_QUICKNET, }, ] diff --git a/src/networks/mod.rs b/src/networks/mod.rs index 5f1b1c2c57fd..05c56e6f711f 100644 --- a/src/networks/mod.rs +++ b/src/networks/mod.rs @@ -105,13 +105,15 @@ pub enum Height { Breeze, Smoke, Ignition, - ActorsV2, + Refuel, + Assembly, Tape, Liftoff, Kumquat, Calico, Persian, Orange, + Claus, Trust, Norwegian, Turbo, @@ -128,6 +130,8 @@ pub enum Height { WatermelonFix2, Dragon, DragonFix, + Phoenix, + Aussie, } impl Default for Height { @@ -142,13 +146,15 @@ impl From for NetworkVersion { Height::Breeze => NetworkVersion::V1, Height::Smoke => NetworkVersion::V2, Height::Ignition => NetworkVersion::V3, - Height::ActorsV2 => NetworkVersion::V4, + Height::Refuel => NetworkVersion::V3, + Height::Assembly => NetworkVersion::V4, Height::Tape => NetworkVersion::V5, Height::Liftoff => NetworkVersion::V5, Height::Kumquat => NetworkVersion::V6, Height::Calico => NetworkVersion::V7, Height::Persian => NetworkVersion::V8, Height::Orange => NetworkVersion::V9, + Height::Claus => NetworkVersion::V9, Height::Trust => NetworkVersion::V10, Height::Norwegian => NetworkVersion::V11, Height::Turbo => NetworkVersion::V12, @@ -165,6 +171,8 @@ impl From for NetworkVersion { Height::WatermelonFix2 => NetworkVersion::V21, Height::Dragon => NetworkVersion::V22, Height::DragonFix => NetworkVersion::V22, + Height::Phoenix => NetworkVersion::V22, + Height::Aussie => NetworkVersion::V23, } } } @@ -205,6 +213,7 @@ pub struct ChainConfig { #[serde(default = "default_policy")] pub policy: Policy, pub eth_chain_id: u32, + pub breeze_gas_tamping_duration: i64, } impl ChainConfig { @@ -220,6 +229,7 @@ impl ChainConfig { height_infos: HEIGHT_INFOS.clone(), policy: Policy::mainnet(), eth_chain_id: ETH_CHAIN_ID as u32, + breeze_gas_tamping_duration: BREEZE_GAS_TAMPING_DURATION, } } @@ -235,6 +245,7 @@ impl ChainConfig { height_infos: HEIGHT_INFOS.clone(), policy: Policy::calibnet(), eth_chain_id: ETH_CHAIN_ID as u32, + breeze_gas_tamping_duration: BREEZE_GAS_TAMPING_DURATION, } } @@ -268,6 +279,7 @@ impl ChainConfig { height_infos: HEIGHT_INFOS.clone(), policy, eth_chain_id: ETH_CHAIN_ID as u32, + breeze_gas_tamping_duration: BREEZE_GAS_TAMPING_DURATION, } } @@ -284,6 +296,7 @@ impl ChainConfig { height_infos: HEIGHT_INFOS.clone(), policy: make_butterfly_policy!(v10), eth_chain_id: ETH_CHAIN_ID as u32, + breeze_gas_tamping_duration: BREEZE_GAS_TAMPING_DURATION, } } @@ -418,17 +431,68 @@ fn get_upgrade_height_from_env(env_var_key: &str) -> Option { None } +#[macro_export] +macro_rules! make_height { + ($id:ident,$epoch:expr) => { + ( + Height::$id, + HeightInfo { + epoch: $epoch, + bundle: None, + }, + ) + }; + ($id:ident,$epoch:expr,$bundle:expr) => { + ( + Height::$id, + HeightInfo { + epoch: $epoch, + bundle: Some(Cid::try_from($bundle).unwrap()), + }, + ) + }; +} + #[cfg(test)] mod tests { use super::*; fn heights_are_present(height_infos: &HashMap) { - assert!(height_infos.get(&Height::Breeze).is_some()); - assert!(height_infos.get(&Height::Smoke).is_some()); - assert!(height_infos.get(&Height::Ignition).is_some()); - assert!(height_infos.get(&Height::ActorsV2).is_some()); - assert!(height_infos.get(&Height::Liftoff).is_some()); - assert!(height_infos.get(&Height::Calico).is_some()); + /// These are required heights that need to be defined for all networks, for, e.g., conformance + /// with `Filecoin.StateGetNetworkParams` RPC method. + const REQUIRED_HEIGHTS: [Height; 27] = [ + Height::Breeze, + Height::Smoke, + Height::Ignition, + Height::Refuel, + Height::Assembly, + Height::Tape, + Height::Liftoff, + Height::Kumquat, + Height::Calico, + Height::Persian, + Height::Orange, + Height::Claus, + Height::Trust, + Height::Norwegian, + Height::Turbo, + Height::Hyperdrive, + Height::Chocolate, + Height::OhSnap, + Height::Skyr, + Height::Shark, + Height::Hygge, + Height::Lightning, + Height::Thunder, + Height::Watermelon, + Height::Dragon, + Height::Phoenix, + Height::Aussie, + ]; + + for height in &REQUIRED_HEIGHTS { + assert!(height_infos.get(height).is_some()); + } } #[test] diff --git a/src/rpc/methods/state.rs b/src/rpc/methods/state.rs index 61da47205383..8e917429445b 100644 --- a/src/rpc/methods/state.rs +++ b/src/rpc/methods/state.rs @@ -2,11 +2,16 @@ // SPDX-License-Identifier: Apache-2.0, MIT mod types; +use fvm_shared3::sector::RegisteredSealProof; +use schemars::JsonSchema; +use serde::{Deserialize, Serialize}; pub use types::*; use crate::blocks::Tipset; use crate::cid_collections::CidHashSet; use crate::libp2p::NetworkMessage; +use crate::lotus_json::lotus_json_with_self; +use crate::networks::{ChainConfig, NetworkChain}; use crate::shim::actors::{market::BalanceTableExt as _, miner::MinerStateExt as _}; use crate::shim::message::Message; use crate::shim::piece::PaddedPieceSize; @@ -57,6 +62,7 @@ macro_rules! for_each_method { $callback!(crate::rpc::state::StateCall); $callback!(crate::rpc::state::StateGetBeaconEntry); $callback!(crate::rpc::state::StateListMessages); + $callback!(crate::rpc::state::StateGetNetworkParams); $callback!(crate::rpc::state::StateNetworkName); $callback!(crate::rpc::state::StateReplay); $callback!(crate::rpc::state::StateSectorGetInfo); @@ -1803,3 +1809,159 @@ impl RpcMethod<3> for StateListMessages { Ok(out) } } + +pub enum StateGetNetworkParams {} + +impl RpcMethod<0> for StateGetNetworkParams { + const NAME: &'static str = "Filecoin.StateGetNetworkParams"; + const PARAM_NAMES: [&'static str; 0] = []; + const API_VERSION: ApiVersion = ApiVersion::V0; + const PERMISSION: Permission = Permission::Read; + + type Params = (); + type Ok = NetworkParams; + + async fn handle( + ctx: Ctx, + (): Self::Params, + ) -> Result { + let config = ctx.state_manager.chain_config(); + let policy = &config.policy; + + // This is the correct implementation, but for conformance with Lotus, + // until resolved there, we have to use a workaround. Replace this + // once a version of Lotus is released with the correct implementation. + // The change is already in the Lotus master branch. + //let supported_proof_types = policy + // .valid_pre_commit_proof_type + // .iter() + // .map(|p| i64::from(*p)) + // .sorted() + // .map(|p| p.into()) + // .collect(); + + use crate::shim::sector::RegisteredSealProofV3::*; + let supported_proof_types = match config.network { + NetworkChain::Mainnet | NetworkChain::Calibnet => { + vec![StackedDRG32GiBV1, StackedDRG64GiBV1] + } + NetworkChain::Butterflynet => { + vec![StackedDRG512MiBV1, StackedDRG32GiBV1, StackedDRG64GiBV1] + } + NetworkChain::Devnet(_) => { + vec![StackedDRG2KiBV1, StackedDRG8MiBV1] + } + }; + + let params = NetworkParams { + network_name: ctx.network_name.clone(), + block_delay_secs: config.block_delay_secs as u64, + consensus_miner_min_power: policy.minimum_consensus_power.clone(), + supported_proof_types, + pre_commit_challenge_delay: policy.pre_commit_challenge_delay, + fork_upgrade_params: ForkUpgradeParams::try_from(config) + .context("Failed to get fork upgrade params")?, + eip155_chain_id: config.eth_chain_id, + }; + + Ok(params) + } +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, JsonSchema)] +#[serde(rename_all = "PascalCase")] +pub struct NetworkParams { + network_name: String, + block_delay_secs: u64, + #[schemars(with = "crate::lotus_json::LotusJson")] + #[serde(with = "crate::lotus_json")] + consensus_miner_min_power: BigInt, + #[schemars(with = "crate::lotus_json::LotusJson")] + supported_proof_types: Vec, + pre_commit_challenge_delay: ChainEpoch, + fork_upgrade_params: ForkUpgradeParams, + #[serde(rename = "Eip155ChainID")] + eip155_chain_id: u32, +} + +lotus_json_with_self!(NetworkParams); + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, JsonSchema)] +#[serde(rename_all = "PascalCase")] +pub struct ForkUpgradeParams { + upgrade_smoke_height: ChainEpoch, + upgrade_breeze_height: ChainEpoch, + upgrade_ignition_height: ChainEpoch, + upgrade_liftoff_height: ChainEpoch, + upgrade_assembly_height: ChainEpoch, + upgrade_refuel_height: ChainEpoch, + upgrade_tape_height: ChainEpoch, + upgrade_kumquat_height: ChainEpoch, + breeze_gas_tamping_duration: ChainEpoch, + upgrade_calico_height: ChainEpoch, + upgrade_persian_height: ChainEpoch, + upgrade_orange_height: ChainEpoch, + upgrade_claus_height: ChainEpoch, + upgrade_trust_height: ChainEpoch, + upgrade_norwegian_height: ChainEpoch, + upgrade_turbo_height: ChainEpoch, + upgrade_hyperdrive_height: ChainEpoch, + upgrade_chocolate_height: ChainEpoch, + upgrade_oh_snap_height: ChainEpoch, + upgrade_skyr_height: ChainEpoch, + upgrade_shark_height: ChainEpoch, + upgrade_hygge_height: ChainEpoch, + upgrade_lightning_height: ChainEpoch, + upgrade_thunder_height: ChainEpoch, + upgrade_watermelon_height: ChainEpoch, + upgrade_dragon_height: ChainEpoch, + upgrade_phoenix_height: ChainEpoch, + // To be added in the next Lotus release + // upgrade_aussie_height: ChainEpoch, +} + +impl TryFrom<&Arc> for ForkUpgradeParams { + type Error = anyhow::Error; + fn try_from(config: &Arc) -> anyhow::Result { + let height_infos = &config.height_infos; + let get_height = |height| -> anyhow::Result { + let height = height_infos + .get(&height) + .context(format!("Height info for {height} not found"))? + .epoch; + Ok(height) + }; + + use crate::networks::Height::*; + Ok(ForkUpgradeParams { + upgrade_smoke_height: get_height(Smoke)?, + upgrade_breeze_height: get_height(Breeze)?, + upgrade_ignition_height: get_height(Ignition)?, + upgrade_liftoff_height: get_height(Liftoff)?, + upgrade_assembly_height: get_height(Assembly)?, + upgrade_refuel_height: get_height(Refuel)?, + upgrade_tape_height: get_height(Tape)?, + upgrade_kumquat_height: get_height(Kumquat)?, + breeze_gas_tamping_duration: config.breeze_gas_tamping_duration, + upgrade_calico_height: get_height(Calico)?, + upgrade_persian_height: get_height(Persian)?, + upgrade_orange_height: get_height(Orange)?, + upgrade_claus_height: get_height(Claus)?, + upgrade_trust_height: get_height(Trust)?, + upgrade_norwegian_height: get_height(Norwegian)?, + upgrade_turbo_height: get_height(Turbo)?, + upgrade_hyperdrive_height: get_height(Hyperdrive)?, + upgrade_chocolate_height: get_height(Chocolate)?, + upgrade_oh_snap_height: get_height(OhSnap)?, + upgrade_skyr_height: get_height(Skyr)?, + upgrade_shark_height: get_height(Shark)?, + upgrade_hygge_height: get_height(Hygge)?, + upgrade_lightning_height: get_height(Lightning)?, + upgrade_thunder_height: get_height(Thunder)?, + upgrade_watermelon_height: get_height(Watermelon)?, + upgrade_dragon_height: get_height(Dragon)?, + upgrade_phoenix_height: get_height(Phoenix)?, + // upgrade_aussie_height: get_height(Aussie)?, + }) + } +} diff --git a/src/shim/version.rs b/src/shim/version.rs index 5e947cac9ece..1b9a288bc217 100644 --- a/src/shim/version.rs +++ b/src/shim/version.rs @@ -60,6 +60,7 @@ impl NetworkVersion { pub const V20: Self = Self(NetworkVersion_latest::new(20)); pub const V21: Self = Self(NetworkVersion_latest::new(21)); pub const V22: Self = Self(NetworkVersion_latest::new(22)); + pub const V23: Self = Self(NetworkVersion_latest::new(23)); } impl Deref for NetworkVersion { diff --git a/src/state_manager/circulating_supply.rs b/src/state_manager/circulating_supply.rs index 4b275ac8bb9c..211515b1f5b2 100644 --- a/src/state_manager/circulating_supply.rs +++ b/src/state_manager/circulating_supply.rs @@ -57,7 +57,7 @@ pub struct GenesisInfo { impl GenesisInfo { pub fn from_chain_config(chain_config: &ChainConfig) -> Self { let ignition_height = chain_config.epoch(Height::Ignition); - let actors_v2_height = chain_config.epoch(Height::ActorsV2); + let actors_v2_height = chain_config.epoch(Height::Assembly); let liftoff_height = chain_config.epoch(Height::Liftoff); let calico_height = chain_config.epoch(Height::Calico); Self { diff --git a/src/tool/subcommands/api_cmd.rs b/src/tool/subcommands/api_cmd.rs index 7be0bb6f164d..31c7200e7881 100644 --- a/src/tool/subcommands/api_cmd.rs +++ b/src/tool/subcommands/api_cmd.rs @@ -669,6 +669,7 @@ fn state_tests_with_tipset( ) -> anyhow::Result> { let mut tests = vec![ RpcTest::identity(StateNetworkName::request(())?), + RpcTest::identity(StateGetNetworkParams::request(())?), RpcTest::identity(StateGetActor::request(( Address::SYSTEM_ACTOR, tipset.key().into(),