Skip to content

Commit febf8d1

Browse files
fix(f3): wrong mainnet network name for joining KAD network (#5609)
Co-authored-by: Hubert Bugaj <[email protected]>
1 parent 8662c91 commit febf8d1

File tree

6 files changed

+40
-10
lines changed

6 files changed

+40
-10
lines changed

f3-sidecar/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
)
1313

1414
type F3Api struct {
15+
GetRawNetworkName func(context.Context) (string, error)
1516
GetTipsetByEpoch func(context.Context, int64) (TipSet, error)
1617
GetTipset func(context.Context, gpbft.TipSetKey) (TipSet, error)
1718
GetHead func(context.Context) (TipSet, error)
@@ -26,7 +27,6 @@ type F3Api struct {
2627

2728
type FilecoinApi struct {
2829
Version func(context.Context) (VersionInfo, error)
29-
StateNetworkName func(context.Context) (string, error)
3030
NetAddrsListen func(context.Context) (peer.AddrInfo, error)
3131
}
3232

f3-sidecar/run.go

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,15 @@ func run(ctx context.Context, rpcEndpoint string, jwt string, f3RpcEndpoint stri
2626
return err
2727
}
2828
defer closer()
29-
var network string
29+
30+
ec, err := NewForestEC(rpcEndpoint, jwt)
31+
if err != nil {
32+
return err
33+
}
34+
35+
var rawNetwork string
3036
for {
31-
network, err = api.StateNetworkName(ctx)
37+
rawNetwork, err = ec.f3api.GetRawNetworkName(ctx)
3238
if err == nil {
3339
logger.Infoln("Forest RPC server is online")
3440
break
@@ -42,11 +48,7 @@ func run(ctx context.Context, rpcEndpoint string, jwt string, f3RpcEndpoint stri
4248
return err
4349
}
4450

45-
p2p, err := createP2PHost(ctx, network)
46-
if err != nil {
47-
return err
48-
}
49-
ec, err := NewForestEC(rpcEndpoint, jwt)
51+
p2p, err := createP2PHost(ctx, rawNetwork)
5052
if err != nil {
5153
return err
5254
}
@@ -72,7 +74,13 @@ func run(ctx context.Context, rpcEndpoint string, jwt string, f3RpcEndpoint stri
7274
logger.Warn("InitialPowerTable is undefined")
7375
m.InitialPowerTable = cid.Undef
7476
}
75-
m.NetworkName = gpbft.NetworkName(network)
77+
// Use "filecoin" as the network name on mainnet, otherwise use the network name. Yes,
78+
// mainnet is called testnetnet in state.
79+
if rawNetwork == "testnetnet" {
80+
m.NetworkName = "filecoin"
81+
} else {
82+
m.NetworkName = gpbft.NetworkName(rawNetwork)
83+
}
7684
versionInfo, err := api.Version(ctx)
7785
if err != nil {
7886
return err

src/networks/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,11 @@ impl ChainConfig {
276276
f3_enabled: true,
277277
f3_consensus: true,
278278
f3_bootstrap_epoch: -1,
279-
f3_initial_power_table: None,
279+
f3_initial_power_table: Some(
280+
"bafy2bzacecklgxd2eksmodvhgurqvorkg3wamgqkrunir3al2gchv2cikgmbu"
281+
.parse()
282+
.expect("invalid f3_initial_power_table"),
283+
),
280284
f3_contract_address: Some(
281285
EthAddress::from_str("0xA19080A1Bcb82Bb61bcb9691EC94653Eb5315716")
282286
.expect("invalid f3 contract eth address"),

src/rpc/methods/f3.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,22 @@ use std::{borrow::Cow, fmt::Display, num::NonZeroU64, str::FromStr as _, sync::A
5959

6060
pub static F3_LEASE_MANAGER: OnceCell<F3LeaseManager> = OnceCell::new();
6161

62+
pub enum GetRawNetworkName {}
63+
64+
impl RpcMethod<0> for GetRawNetworkName {
65+
const NAME: &'static str = "F3.GetRawNetworkName";
66+
const PARAM_NAMES: [&'static str; 0] = [];
67+
const API_PATHS: BitFlags<ApiPaths> = ApiPaths::all();
68+
const PERMISSION: Permission = Permission::Read;
69+
70+
type Params = ();
71+
type Ok = String;
72+
73+
async fn handle(ctx: Ctx<impl Blockstore>, (): Self::Params) -> Result<Self::Ok, ServerError> {
74+
Ok(ctx.network_name.clone())
75+
}
76+
}
77+
6278
pub enum GetTipsetByEpoch {}
6379
impl RpcMethod<1> for GetTipsetByEpoch {
6480
const NAME: &'static str = "F3.GetTipsetByEpoch";

src/rpc/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ macro_rules! for_each_rpc_method {
258258
$callback!($crate::rpc::wallet::WalletVerify);
259259

260260
// f3
261+
$callback!($crate::rpc::f3::GetRawNetworkName);
261262
$callback!($crate::rpc::f3::F3GetCertificate);
262263
$callback!($crate::rpc::f3::F3GetECPowerTable);
263264
$callback!($crate::rpc::f3::F3GetF3PowerTable);

src/tool/subcommands/api_cmd/test_snapshots_ignored.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ F3.GetManifestFromContract
44
F3.GetParent
55
F3.GetParticipatingMinerIDs
66
F3.GetPowerTable
7+
F3.GetRawNetworkName
78
F3.GetTipset
89
F3.GetTipsetByEpoch
910
F3.ProtectPeer

0 commit comments

Comments
 (0)