fix: sealed header should not be immutable borrowed (#6456)

This commit is contained in:
yjh
2024-02-08 03:26:26 +08:00
committed by GitHub
parent 7a57d89575
commit 29e8aab08a
44 changed files with 464 additions and 385 deletions

View File

@ -60,8 +60,8 @@ fn header_provider_example<T: HeaderProvider>(provider: T, number: u64) -> eyre:
// Can also query the header by hash!
let header_by_hash =
provider.header(&sealed_header.hash)?.ok_or(eyre::eyre!("header by hash not found"))?;
assert_eq!(sealed_header.header, header_by_hash);
provider.header(&sealed_header.hash())?.ok_or(eyre::eyre!("header by hash not found"))?;
assert_eq!(sealed_header.header(), &header_by_hash);
// The header's total difficulty is stored in a separate table, so we have a separate call for
// it. This is not needed for post PoS transition chains.
@ -123,19 +123,21 @@ fn block_provider_example<T: BlockReader>(provider: T, number: u64) -> eyre::Res
let sealed_block = block.clone().seal_slow();
// Can also query the block by hash directly
let block_by_hash =
provider.block_by_hash(sealed_block.hash)?.ok_or(eyre::eyre!("block by hash not found"))?;
let block_by_hash = provider
.block_by_hash(sealed_block.hash())?
.ok_or(eyre::eyre!("block by hash not found"))?;
assert_eq!(block, block_by_hash);
// Or by relying in the internal conversion
let block_by_hash2 =
provider.block(sealed_block.hash.into())?.ok_or(eyre::eyre!("block by hash not found"))?;
let block_by_hash2 = provider
.block(sealed_block.hash().into())?
.ok_or(eyre::eyre!("block by hash not found"))?;
assert_eq!(block, block_by_hash2);
// Or you can also specify the datasource. For this provider this always return `None`, but
// the blockchain tree is also able to access pending state not available in the db yet.
let block_by_hash3 = provider
.find_block_by_hash(sealed_block.hash, BlockSource::Any)?
.find_block_by_hash(sealed_block.hash(), BlockSource::Any)?
.ok_or(eyre::eyre!("block hash not found"))?;
assert_eq!(block, block_by_hash3);
@ -144,7 +146,7 @@ fn block_provider_example<T: BlockReader>(provider: T, number: u64) -> eyre::Res
// Can query the block's withdrawals (via the `WithdrawalsProvider`)
let _withdrawals =
provider.withdrawals_by_block(sealed_block.hash.into(), sealed_block.timestamp)?;
provider.withdrawals_by_block(sealed_block.hash().into(), sealed_block.timestamp)?;
Ok(())
}