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

feat(f3): add f3_* fields to chain config #4871

Merged
merged 7 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions f3-sidecar/ffi_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ import (
var GoF3NodeImpl GoF3Node

type GoF3Node interface {
run(rpc_endpoint string, f3_rpc_endpoint string, initial_power_table string, finality int64, f3_root string, manifest_server string) bool
run(rpc_endpoint string, f3_rpc_endpoint string, initial_power_table string, bootstrap_epoch int64, finality int64, f3_root string, manifest_server string) bool
}

//export CGoF3Node_run
func CGoF3Node_run(rpc_endpoint C.StringRef, f3_rpc_endpoint C.StringRef, initial_power_table C.StringRef, finality C.int64_t, f3_root C.StringRef, manifest_server C.StringRef, slot *C.void, cb *C.void) {
resp := GoF3NodeImpl.run(newString(rpc_endpoint), newString(f3_rpc_endpoint), newString(initial_power_table), newC_int64_t(finality), newString(f3_root), newString(manifest_server))
func CGoF3Node_run(rpc_endpoint C.StringRef, f3_rpc_endpoint C.StringRef, initial_power_table C.StringRef, bootstrap_epoch C.int64_t, finality C.int64_t, f3_root C.StringRef, manifest_server C.StringRef, slot *C.void, cb *C.void) {
resp := GoF3NodeImpl.run(newString(rpc_endpoint), newString(f3_rpc_endpoint), newString(initial_power_table), newC_int64_t(bootstrap_epoch), newC_int64_t(finality), newString(f3_root), newString(manifest_server))
resp_ref, buffer := cvt_ref(cntC_bool, refC_bool)(&resp)
C.GoF3Node_run_cb(unsafe.Pointer(cb), resp_ref, unsafe.Pointer(slot))
runtime.KeepAlive(resp)
Expand Down
4 changes: 2 additions & 2 deletions f3-sidecar/ffi_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ type f3Impl struct {
ctx context.Context
}

func (f3 *f3Impl) run(rpc_endpoint string, f3_rpc_endpoint string, initial_power_table string, finality int64, db string, manifest_server string) bool {
err := run(f3.ctx, rpc_endpoint, f3_rpc_endpoint, initial_power_table, finality, db, manifest_server)
func (f3 *f3Impl) run(rpc_endpoint string, f3_rpc_endpoint string, initial_power_table string, bootstrap_epoch int64, finality int64, db string, manifest_server string) bool {
err := run(f3.ctx, rpc_endpoint, f3_rpc_endpoint, initial_power_table, bootstrap_epoch, finality, db, manifest_server)
return err == nil
}

Expand Down
4 changes: 3 additions & 1 deletion f3-sidecar/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ func main() {
flag.StringVar(&f3RpcEndpoint, "f3-rpc", "127.0.0.1:23456", "The RPC endpoint F3 sidecar listens on")
var initialPowerTable string
flag.StringVar(&initialPowerTable, "initial-power-table", "", "The CID of the initial power table")
var bootstrapEpoch int64
flag.Int64Var(&bootstrapEpoch, "bootstrap", -1, "F3 bootstrap epoch")
var finality int64
flag.Int64Var(&finality, "finality", 900, "chain finality epochs")
var root string
Expand All @@ -34,7 +36,7 @@ func main() {

ctx := context.Background()

err := run(ctx, rpcEndpoint, f3RpcEndpoint, initialPowerTable, finality, root, manifestServer)
err := run(ctx, rpcEndpoint, f3RpcEndpoint, initialPowerTable, bootstrapEpoch, finality, root, manifestServer)
if err != nil {
panic(err)
}
Expand Down
10 changes: 8 additions & 2 deletions f3-sidecar/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/libp2p/go-libp2p/core/peer"
)

func run(ctx context.Context, rpcEndpoint string, f3RpcEndpoint string, initialPowerTable string, finality int64, f3Root string, manifestServer string) error {
func run(ctx context.Context, rpcEndpoint string, f3RpcEndpoint string, initialPowerTable string, bootstrapEpoch int64, finality int64, f3Root string, manifestServer string) error {
api := FilecoinApi{}
closer, err := jsonrpc.NewClient(context.Background(), rpcEndpoint, "Filecoin", &api, nil)
if err != nil {
Expand Down Expand Up @@ -82,7 +82,13 @@ func run(ctx context.Context, rpcEndpoint string, f3RpcEndpoint string, initialP
return err
}
m.EC.Finality = finality
m.BootstrapEpoch = max(m.EC.Finality+1, head.Epoch()-m.EC.Finality+1)
if bootstrapEpoch < 0 {
// This is temporary logic to make the dummy bootstrap epoch work locally.
// It should be removed once bootstrapEpochs are determinted.
m.BootstrapEpoch = max(m.EC.Finality+1, head.Epoch()-m.EC.Finality+1)
} else {
m.BootstrapEpoch = bootstrapEpoch
}
m.CommitteeLookback = 5
// m.Pause = true

Expand Down
32 changes: 28 additions & 4 deletions src/daemon/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,6 @@ pub(super) async fn start(
.ok()
.and_then(|v| match v.parse::<i64>() {
Ok(f) if f > 0 => {
tracing::info!("Using F3 finality {f} set by FOREST_F3_FINALITY");
Some(f)
}
_ => {
Expand All @@ -428,21 +427,46 @@ pub(super) async fn start(
None
}
})
.inspect(|i| {
Copy link
Member

Choose a reason for hiding this comment

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

It'd be great to de-clunk this method which is already pretty bloated. How about moving the F3 init + config + service into f3/?

For readability, I'd imagine the end the end usage to be along lines of:

services.spawn_block({
  f3::service(...)
})

After moving it into a separate module, it'd be great to have some basic unit tests if possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

de-clunked the method and added unit test

tracing::info!("Using F3 finality {i} set by FOREST_F3_FINALITY");
})
.unwrap_or(chain_config.policy.chain_finality);
let default_f3_root = config.client.data_dir.join(format!("f3/{}", config.chain));
let f3_bootstrap_epoch = chain_config.f3_bootstrap_epoch;
let f3_initial_power_table = chain_config.f3_initial_power_table;
let f3_mainfest_server = chain_config.f3_mainfest_server;
move || {
// This will be used post-bootstrap to hard-code the initial F3's initial power table CID.
// Read from an environment variable for now before the hard-coded value is determined.
let initial_power_table =
std::env::var("FOREST_F3_INITIAL_POWER_TABLE").unwrap_or_default();
std::env::var("FOREST_F3_INITIAL_POWER_TABLE").ok().and_then(|i|i.parse().ok()).inspect(|i| {
tracing::info!(
"Using F3 initial power table cid {i} set by FOREST_F3_INITIAL_POWER_TABLE"
)
}).unwrap_or(f3_initial_power_table);
let bootstrap_epoch = std::env::var("FOREST_F3_BOOTSTRAP_EPOCH")
.ok()
.and_then(|i| i.parse().ok())
.inspect(|i| {
tracing::info!(
"Using F3 bootstrap epoch {i} set by FOREST_F3_BOOTSTRAP_EPOCH"
)
})
.unwrap_or(f3_bootstrap_epoch);
let manifest_server = std::env::var("FOREST_F3_MANIFEST_SERVER").ok().and_then(|i|i.parse().ok()).inspect(|i| {
tracing::info!(
"Using F3 manifest server {i} set by FOREST_F3_MANIFEST_SERVER"
)
}).or(f3_mainfest_server);
crate::f3::run_f3_sidecar_if_enabled(
format!("http://{rpc_address}/rpc/v1"),
crate::rpc::f3::get_f3_rpc_endpoint().to_string(),
initial_power_table,
initial_power_table.to_string(),
bootstrap_epoch,
finality,
std::env::var("FOREST_F3_ROOT")
.unwrap_or(default_f3_root.display().to_string()),
std::env::var("FOREST_F3_MANIFEST_SERVER").unwrap_or_default(),
manifest_server.map(|i|i.to_string()).unwrap_or_default(),
);
Ok(())
}
Expand Down
1 change: 1 addition & 0 deletions src/f3/go_ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub trait GoF3Node {
rpc_endpoint: String,
f3_rpc_endpoint: String,
initial_power_table: String,
bootstrap_epoch: i64,
finality: i64,
f3_root: String,
manifest_server: String,
Expand Down
2 changes: 2 additions & 0 deletions src/f3/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub fn run_f3_sidecar_if_enabled(
_rpc_endpoint: String,
_f3_rpc_endpoint: String,
_initial_power_table: String,
_bootstrap_epoch: i64,
_finality: i64,
_f3_root: String,
_manifest_server: String,
Expand All @@ -23,6 +24,7 @@ pub fn run_f3_sidecar_if_enabled(
_rpc_endpoint,
_f3_rpc_endpoint,
_initial_power_table,
_bootstrap_epoch,
_finality,
_f3_root,
_manifest_server,
Expand Down
28 changes: 27 additions & 1 deletion src/networks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,9 @@ pub struct ChainConfig {
pub breeze_gas_tamping_duration: i64,
// FIP0081 gradually comes into effect over this many epochs.
pub fip0081_ramp_duration_epochs: u64,
pub f3_bootstrap_epoch: i64,
pub f3_initial_power_table: Cid,
pub f3_mainfest_server: Option<Cid>,
}

impl ChainConfig {
Expand All @@ -249,6 +252,13 @@ impl ChainConfig {
breeze_gas_tamping_duration: BREEZE_GAS_TAMPING_DURATION,
// 1 year on mainnet
fip0081_ramp_duration_epochs: 365 * EPOCHS_IN_DAY as u64,
f3_bootstrap_epoch: -1,
f3_initial_power_table: Default::default(),
f3_mainfest_server: Some(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These values are from Lotus but I suspect f3_mainfest_server will be deprecated once F3 is fully bootstrapped to avoid single point network dependencies

Copy link
Member

Choose a reason for hiding this comment

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

It'd best to put this comment in the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

"12D3KooWENMwUF9YxvQxar7uBWJtZkA6amvK4xWmKXfSiHUo2Qq7"
.parse()
.expect("Invalid CID"),
),
}
}

Expand All @@ -270,6 +280,13 @@ impl ChainConfig {
breeze_gas_tamping_duration: BREEZE_GAS_TAMPING_DURATION,
// 3 days on calibnet
fip0081_ramp_duration_epochs: 3 * EPOCHS_IN_DAY as u64,
f3_bootstrap_epoch: -1,
f3_initial_power_table: Default::default(),
f3_mainfest_server: Some(
"12D3KooWS9vD9uwm8u2uPyJV32QBAhKAmPYwmziAgr3Xzk2FU1Mr"
.parse()
.expect("Invalid CID"),
),
}
}

Expand All @@ -288,12 +305,14 @@ impl ChainConfig {
breeze_gas_tamping_duration: BREEZE_GAS_TAMPING_DURATION,
// Devnet ramp is 200 epochs in Lotus (subject to change).
fip0081_ramp_duration_epochs: env_or_default(ENV_PLEDGE_RULE_RAMP, 200),
f3_bootstrap_epoch: -1,
f3_initial_power_table: Default::default(),
f3_mainfest_server: None,
}
}

pub fn butterflynet() -> Self {
use butterflynet::*;

Self {
network: NetworkChain::Butterflynet,
genesis_cid: Some(GENESIS_CID.to_string()),
Expand All @@ -313,6 +332,13 @@ impl ChainConfig {
ENV_PLEDGE_RULE_RAMP,
365 * EPOCHS_IN_DAY as u64,
),
f3_bootstrap_epoch: -1,
f3_initial_power_table: Default::default(),
f3_mainfest_server: Some(
"12D3KooWJr9jy4ngtJNR7JC1xgLFra3DjEtyxskRYWvBK9TC3Yn6"
.parse()
.expect("Invalid CID"),
),
}
}

Expand Down
Loading