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

Remove theft reporting #677

Merged
merged 3 commits into from Jul 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
72 changes: 0 additions & 72 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion README.md
Expand Up @@ -64,7 +64,6 @@ The Substrate runtime makes use of various custom pallets that are found in the
- [oracle](crates/oracle): Trusted providers use this to set exchange rates and Bitcoin fee estimates.
- [redeem](crates/redeem): Handles redeeming of interBTC for BTC on Bitcoin.
- [refund](crates/refund): Handles refunds for when a vault receives more BTC than it can cover.
- [relay](crates/relay): Handles block submission and theft reporting.
- [replace](crates/replace): Handles replacing vaults.
- [reward](crates/reward): Scalable reward distribution.
- [security](crates/security): Handles status and error changes.
Expand Down
48 changes: 47 additions & 1 deletion crates/btc-relay/src/benchmarking.rs
Expand Up @@ -24,7 +24,7 @@ fn mine_genesis<T: Config>(account_id: T::AccountId, address: &BtcAddress, heigh
let raw_block_header = RawBlockHeader::from_bytes(&block.header.try_format().unwrap()).unwrap();
let block_header = BtcRelay::<T>::parse_raw_block_header(&raw_block_header).unwrap();

BtcRelay::<T>::initialize(account_id, block_header, height).unwrap();
BtcRelay::<T>::_initialize(account_id, block_header, height).unwrap();

block
}
Expand Down Expand Up @@ -76,6 +76,52 @@ fn mine_block_with_one_tx<T: Config>(
}

benchmarks! {
initialize {
let height = 0u32;
let origin: T::AccountId = account("Origin", 0, 0);
let stake = 100u32;

let address = BtcAddress::P2PKH(H160::from([0; 20]));
let block = BlockBuilder::new()
.with_version(4)
.with_coinbase(&address, 50, 3)
.with_timestamp(1588813835)
.mine(U256::from(2).pow(254.into())).unwrap();
let block_header = RawBlockHeader::from_bytes(&block.header.try_format().unwrap()).unwrap();
}: _(RawOrigin::Signed(origin), block_header, height)

store_block_header {
let origin: T::AccountId = account("Origin", 0, 0);

let address = BtcAddress::P2PKH(H160::from([0; 20]));
let height = 0;
let stake = 100u32;

let init_block = BlockBuilder::new()
.with_version(4)
.with_coinbase(&address, 50, 3)
.with_timestamp(1588813835)
.mine(U256::from(2).pow(254.into())).unwrap();

let init_block_hash = init_block.header.hash;
let raw_block_header = RawBlockHeader::from_bytes(&init_block.header.try_format().unwrap())
.expect("could not serialize block header");
let block_header = BtcRelay::<T>::parse_raw_block_header(&raw_block_header).unwrap();

BtcRelay::<T>::_initialize(origin.clone(), block_header, height).unwrap();

let block = BlockBuilder::new()
.with_previous_hash(init_block_hash)
.with_version(4)
.with_coinbase(&address, 50, 3)
.with_timestamp(1588814835)
.mine(U256::from(2).pow(254.into())).unwrap();

let raw_block_header = RawBlockHeader::from_bytes(&block.header.try_format().unwrap())
.expect("could not serialize block header");

}: _(RawOrigin::Signed(origin), raw_block_header)

verify_and_validate_transaction {
let origin: T::AccountId = account("Origin", 0, 0);

Expand Down
58 changes: 58 additions & 0 deletions crates/btc-relay/src/default_weights.rs
Expand Up @@ -34,6 +34,8 @@ use sp_std::marker::PhantomData;

/// Weight functions needed for btc_relay.
pub trait WeightInfo {
fn initialize() -> Weight;
fn store_block_header() -> Weight;
fn verify_and_validate_transaction() -> Weight;
fn verify_transaction_inclusion() -> Weight;
fn validate_transaction() -> Weight;
Expand All @@ -42,6 +44,34 @@ pub trait WeightInfo {
/// Weights for btc_relay using the Substrate node and recommended hardware.
pub struct SubstrateWeight<T>(PhantomData<T>);
impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Storage: Security ParachainStatus (r:1 w:0)
// Storage: BTCRelay BestBlock (r:1 w:1)
// Storage: BTCRelay ChainCounter (r:1 w:1)
// Storage: BTCRelay Chains (r:1 w:1)
// Storage: Security ActiveBlockCount (r:1 w:0)
// Storage: BTCRelay ChainsHashes (r:0 w:1)
// Storage: BTCRelay StartBlockHeight (r:0 w:1)
// Storage: BTCRelay BestBlockHeight (r:0 w:1)
// Storage: BTCRelay ChainsIndex (r:0 w:1)
// Storage: BTCRelay BlockHeaders (r:0 w:1)
fn initialize() -> Weight {
(52_878_000 as Weight)
.saturating_add(T::DbWeight::get().reads(5 as Weight))
.saturating_add(T::DbWeight::get().writes(8 as Weight))
}
// Storage: Security ParachainStatus (r:1 w:0)
// Storage: BTCRelay BlockHeaders (r:2 w:1)
// Storage: BTCRelay ChainsIndex (r:1 w:1)
// Storage: BTCRelay DisableDifficultyCheck (r:1 w:0)
// Storage: BTCRelay ChainsHashes (r:1 w:1)
// Storage: Security ActiveBlockCount (r:1 w:0)
// Storage: BTCRelay BestBlock (r:0 w:1)
// Storage: BTCRelay BestBlockHeight (r:0 w:1)
fn store_block_header() -> Weight {
(68_306_000 as Weight)
.saturating_add(T::DbWeight::get().reads(7 as Weight))
.saturating_add(T::DbWeight::get().writes(5 as Weight))
}
// Storage: Security ParachainStatus (r:1 w:0)
// Storage: BTCRelay DisableInclusionCheck (r:1 w:0)
// Storage: BTCRelay BestBlockHeight (r:1 w:0)
Expand Down Expand Up @@ -73,6 +103,34 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {

// For backwards compatibility and tests
impl WeightInfo for () {
// Storage: Security ParachainStatus (r:1 w:0)
// Storage: BTCRelay BestBlock (r:1 w:1)
// Storage: BTCRelay ChainCounter (r:1 w:1)
// Storage: BTCRelay Chains (r:1 w:1)
// Storage: Security ActiveBlockCount (r:1 w:0)
// Storage: BTCRelay ChainsHashes (r:0 w:1)
// Storage: BTCRelay StartBlockHeight (r:0 w:1)
// Storage: BTCRelay BestBlockHeight (r:0 w:1)
// Storage: BTCRelay ChainsIndex (r:0 w:1)
// Storage: BTCRelay BlockHeaders (r:0 w:1)
fn initialize() -> Weight {
(52_878_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(5 as Weight))
.saturating_add(RocksDbWeight::get().writes(8 as Weight))
}
// Storage: Security ParachainStatus (r:1 w:0)
// Storage: BTCRelay BlockHeaders (r:2 w:1)
// Storage: BTCRelay ChainsIndex (r:1 w:1)
// Storage: BTCRelay DisableDifficultyCheck (r:1 w:0)
// Storage: BTCRelay ChainsHashes (r:1 w:1)
// Storage: Security ActiveBlockCount (r:1 w:0)
// Storage: BTCRelay BestBlock (r:0 w:1)
// Storage: BTCRelay BestBlockHeight (r:0 w:1)
fn store_block_header() -> Weight {
(68_306_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(7 as Weight))
.saturating_add(RocksDbWeight::get().writes(5 as Weight))
}
// Storage: Security ParachainStatus (r:1 w:0)
// Storage: BTCRelay DisableInclusionCheck (r:1 w:0)
// Storage: BTCRelay BestBlockHeight (r:1 w:0)
Expand Down