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

don't rely on drand networks for past beacons #4838

Open
2 tasks
LesnyRumcajs opened this issue Oct 2, 2024 · 1 comment
Open
2 tasks

don't rely on drand networks for past beacons #4838

LesnyRumcajs opened this issue Oct 2, 2024 · 1 comment
Labels
Type: Bug Something isn't working Type: Task Discrete task to implement

Comments

@LesnyRumcajs
Copy link
Member

LesnyRumcajs commented Oct 2, 2024

Summary

An excellent summary is provided in filecoin-project/lotus#12527 (comment)

tl;dr we shouldn't rely on drand providing endpoints for historical beacons. It's both not scalable, incorrect in certain epochs and not reliable.

The downside of this is reduced performance when requesting beacon entries for really old epochs, e.g., first epoch of calibnet.

Completion Criteria

  • Identify places where we call the drand servers for beacon data - if the data is available on chain, we should not do this and get that tipset's drand entry. There is at least one -
    impl RpcMethod<1> for StateGetBeaconEntry {
    const NAME: &'static str = "Filecoin.StateGetBeaconEntry";
    const PARAM_NAMES: [&'static str; 1] = ["epoch"];
    const API_PATHS: ApiPaths = ApiPaths::V1;
    const PERMISSION: Permission = Permission::Read;
    type Params = (ChainEpoch,);
    type Ok = BeaconEntry;
    async fn handle(
    ctx: Ctx<impl Blockstore>,
    (epoch,): Self::Params,
    ) -> Result<Self::Ok, ServerError> {
    {
    let genesis_timestamp = ctx.chain_store().genesis_block_header().timestamp as i64;
    let block_delay = ctx.chain_config().block_delay_secs as i64;
    // Give it a 1s clock drift buffer
    let epoch_timestamp = genesis_timestamp + block_delay * epoch + 1;
    let now_timestamp = chrono::Utc::now().timestamp();
    match epoch_timestamp.saturating_sub(now_timestamp) {
    diff if diff > 0 => {
    tokio::time::sleep(Duration::from_secs(diff as u64)).await;
    }
    _ => {}
    };
    }
    let (_, beacon) = ctx.beacon().beacon_for_epoch(epoch)?;
    let network_version = ctx.state_manager.get_network_version(epoch);
    let round = beacon.max_beacon_round_for_epoch(network_version, epoch);
    let entry = beacon.entry(round).await?;
    Ok(entry)
    }
    }
  • assert that performance is similar to Lotus's, both calibnet and mainnet.

Additional Links & Resources

@LesnyRumcajs LesnyRumcajs added the Type: Task Discrete task to implement label Oct 2, 2024
@LesnyRumcajs
Copy link
Member Author

Also, on mainnet, getting old entry doesn't work.

❯ time curl --silent -X POST -H "Content-Type: application/json" \
             --data '{"jsonrpc":"2.0","id":2,"method":"Filecoin.StateGetBeaconEntry","params": [ 1 ] }' \
             "http://127.0.0.1:2345/rpc/v1"
{"jsonrpc":"2.0","id":2,"error":{"code":-32603,"message":"Aggregated errors:\n"}}
________________________________________________________
Executed in  884.48 secs      fish           external
   usr time    8.36 millis  384.00 micros    7.98 millis
   sys time   21.31 millis   92.00 micros   21.21 millis

@LesnyRumcajs LesnyRumcajs added the Type: Bug Something isn't working label Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Something isn't working Type: Task Discrete task to implement
Projects
Status: Ready
Development

No branches or pull requests

1 participant