ethereum / trin

An Ethereum portal client: a json-rpc server with nearly instant sync, and low CPU & storage usage
365 stars 113 forks source link

fix: process_beacon_block() doesn't decode all types properly #1416

Closed KolbyML closed 3 weeks ago

KolbyML commented 3 weeks ago

What was wrong?

decoding beacon blocks, to processed blocks fails

How was it fixed?

So bloom is just a 256 bit number, it isn't encoded in RLP.

For transactions I used the wrong decode function for this use case

I tried to write some tests

#[cfg(test)]
mod tests {
    use crate::era::manager::EraManager;

    use super::*;

    use rstest::rstest;
    use serde_json::Value;

    #[tokio::test]
    async fn hi() {
        let mut era_manager = EraManager::new(19000000).await.unwrap();
        let block = era_manager.get_next_block().await.unwrap();
    }

    #[rstest]
    #[case("bellatrix/SignedBeaconBlock/ssz_random/case_0")]
    #[case("bellatrix/SignedBeaconBlock/ssz_random/case_1")]
    #[case("capella/SignedBeaconBlock/ssz_random/case_0")]
    #[case("capella/SignedBeaconBlock/ssz_random/case_1")]
    #[case("deneb/SignedBeaconBlock/ssz_random/case_0")]
    #[case("deneb/SignedBeaconBlock/ssz_random/case_1")]
    fn serde_signed_beacon_block_bellatrix(#[case] case: &str) {
        let value = std::fs::read_to_string(format!("../test_assets/beacon/{case}/value.yaml"))
            .expect("cannot find test asset");
        let value: Value = serde_yaml::from_str(&value).unwrap();
        let content: SignedBeaconBlock = serde_json::from_value(value.clone()).unwrap();
        content.process_beacon_block().unwrap();
    }
}

My second test was meant to be the gold ticket, but the test data we use for consensus testing has invalid transactions, but work for testing consensus types, as the consensus transaction type is Opaque

So I just used the first test to verified it works.

I think I will make an issue for dumping the valid SignedBeaconBlock so we can include this test