FuelLabs / fuel-core

Rust full node implementation of the Fuel v2 protocol.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

transactions() on beta 5 has some issues with cursors.

andy-thomason opened this issue · comments

Hi Everyone. I'm enjoying exploring the codebase and doing some experiments with the public beta 5 endpoint.

I don't have a particular template to work from, so I'm making some assumptions here:

Given

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let client = FuelClient::new("https://beta-5.fuel.network/graphql")?;

    get_transactions(&client, 0).await?;

    Ok(())
}

async fn get_transactions(client: &FuelClient, start_block: u32) -> anyhow::Result<()> {
    use fuel_core_client::client::types::primitives::TransactionId;
    let tx = TransactionId::zeroed();
    let mut cursor = (start_block != 0).then_some(format!("{start_block}#0x{tx}"));
    let results = 10;
    for _ in 0.. {
        let req = PaginationRequest {cursor, results, direction: PageDirection::Forward };
        let txs = client.transactions(req).await?;

        cursor = txs.cursor;

        for tx in txs.results {
            println!("{tx:#?}");
        }
    }
    Ok(())
}

Two things go wrong.

  1. If we initialise with a cursor with a form of block#0x0000...0000 then the endpoint hangs.
  2. If we initialise with a cursor of None, the next cursor has the block number formatted in hex
    such as Some("0000000a#0x49c6fee039066353084bdf8585930bba4cd9e89433c2abce3f8c7c35c9b8ac4e")
    which fails because the endpoint expects a decimal number.

Am I being an idiot, or should these two expectations be met?

I'm using the release/v0.22.1 fuel-core.

Nice finds! These are real bugs, the SortedTxCursor decodes block height using u32::from_str(block_height) but the display impl for BlockHeight does indeed use <Self as fmt::LowerHex>::fmt(&self, f).

BlockHeight used to be a type-alias for u32, and this bug must've slipped in when we migrated to using a dedicated newtype for BlockHeight.

Oddly, this should've been covered by the tests::tx::get_transactions() integration test so we need to do some investigation into why this test is passing.

Hi @andy-thomason 👋,

Thank you for taking the initiative to open this bug report in fuel-core! You taking the time to report back on the bugs you found shows a lot about your commitment to open source and your contribution is highly valued! 🌟

Given your interest and expertise, we believe you would be an excellent candidate for the Fuel Developer Champions program. It's a fantastic opportunity to collaborate more closely with our team, deepen your engagement, get access to bounty programs for members of the program, champions swag, and more initiatives are in the works as the program continues to evolve. 🚀

Please consider joining us by checking out the start-here repo for the program.

Looking forward to welcoming you into the program!

Ben

Thanks for the encouragement, Ben.

I'll check with our team at Superchain Network about the programme.

It is good to see new projects in this space and it is all great food for our cross chain
indexer investigations.

We are setting up a node on our network to do more tests and I'm just building out
a proof-of-concept for a block sucker and log scraper - stage one on our journey.

Andy.