Skip to content

Commit

Permalink
v0.1.6 (#43)
Browse files Browse the repository at this point in the history
Co-authored-by: David Salami <[email protected]>
  • Loading branch information
seunlanlege and Wizdave97 authored Oct 9, 2023
1 parent ad84e61 commit c75ed34
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Hyperbridge
Hyperbridge is a hyper-scalable, bridge network. Powered by zkSNARKs, Secured by Polkadot.
Hyperbridge is a hyper-scalable, interoperability coprocessor.

## Running a local tesnet with zombienet
1. Download the zombienet binary for your os from https://github.com/paritytech/zombienet
Expand Down
8 changes: 5 additions & 3 deletions parachain/chainspec/gargantua.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{
"name": "Hyperbridge (Gargantua)",
"id": "gargantua",
"id": "gargantuan",
"chainType": "Live",
"bootNodes": [],
"bootNodes": [
" /ip4/34.78.130.110/tcp/30333/p2p/12D3KooWMRRsnAgJ1hjxCj3uJXPkauHqhP2BbbP4M5XF8xVJpeLX"
],
"telemetryEndpoints": null,
"protocolId": "gargantua",
"protocolId": "gargantuan",
"properties": {
"ss58Format": 42,
"tokenDecimals": 12,
Expand Down
7 changes: 1 addition & 6 deletions parachain/modules/ismp/pallet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ pub mod pallet {
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
fn on_initialize(_n: BlockNumberFor<T>) -> Weight {
// return Mmr finalization weight here
// todo: return correct Mmr finalization weight here
<T as Config>::WeightInfo::on_finalize(Self::number_of_leaves() as u32)
}

Expand Down Expand Up @@ -785,11 +785,6 @@ impl<T: Config> Pallet<T> {
Nodes::<T>::insert(pos, node)
}

/// Returns the number of leaves in the mmr
fn get_num_leaves() -> LeafIndex {
NumberOfLeaves::<T>::get()
}

/// Set the number of leaves in the mmr
fn set_num_leaves(num_leaves: LeafIndex) {
NumberOfLeaves::<T>::put(num_leaves)
Expand Down
13 changes: 6 additions & 7 deletions parachain/modules/ismp/pallet/src/mmr/mmr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::{
utils::NodesUtils,
},
primitives::{Error, Proof},
Config,
Config, Pallet,
};
use ismp::mmr::{DataOrHash, Leaf, MmrHasher, NodeIndex};
use sp_core::H256;
Expand All @@ -36,7 +36,6 @@ where
Storage<StorageType, T>: mmr_lib::MMRStore<DataOrHash>,
{
mmr: mmr_lib::MMR<DataOrHash, MmrHasher<Host<T>>, Storage<StorageType, T>>,
leaves: NodeIndex,
}

impl<StorageType, T> Mmr<StorageType, T>
Expand All @@ -47,7 +46,7 @@ where
/// Create a pointer to an existing MMR with given number of leaves.
pub fn new(leaves: NodeIndex) -> Self {
let size = NodesUtils::new(leaves).size();
Self { mmr: mmr_lib::MMR::new(size, Default::default()), leaves }
Self { mmr: mmr_lib::MMR::new(size, Default::default()) }
}
}

Expand All @@ -61,10 +60,10 @@ where
/// Returns the element position (index) and number of leaves in the MMR.
pub fn push(mut self, leaf: Leaf) -> Option<(NodeIndex, NodeIndex)> {
let position = self.mmr.push(DataOrHash::Data(leaf)).map_err(|_| Error::Push).ok()?;
let num_leaves = self.leaves + 1;
self.leaves = num_leaves;
// Leaf index for the new leaf is the previous number of leaves
let leaf_index = Pallet::<T>::number_of_leaves();
self.mmr.commit().ok()?;
Some((position, num_leaves))
Some((position, leaf_index))
}

/// Calculate the new MMR's root hash.
Expand Down Expand Up @@ -96,7 +95,7 @@ where
})
.collect::<Result<Vec<_>, Error>>()?;
log::trace!(target: "runtime::mmr", "Positions {:?}", positions);
let leaf_count = self.leaves;
let leaf_count = Pallet::<T>::number_of_leaves();
self.mmr
.gen_proof(positions.clone())
.map_err(|_| Error::GenerateProof)
Expand Down
2 changes: 1 addition & 1 deletion parachain/modules/ismp/pallet/src/mmr/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ where
elems.iter().map(|elem| elem.hash::<Host<T>>()).collect::<Vec<_>>()
);

let leaves = Pallet::<T>::get_num_leaves();
let leaves = Pallet::<T>::number_of_leaves();
let size = NodesUtils::new(leaves).size();

if pos != size {
Expand Down
2 changes: 1 addition & 1 deletion parachain/node/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hyperbridge"
version = "0.1.5"
version = "0.1.6"
authors = ["Polytope Labs <[email protected]>"]
description = "The hyperbridge coprocessor node"
edition = "2021"
Expand Down
2 changes: 1 addition & 1 deletion parachain/node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fn load_spec(id: &str) -> std::result::Result<Box<dyn ChainSpec>, String> {
let id = u32::from_str(id).expect("can't parse Id into u32");
Box::new(chain_spec::development_config(id))
},
"gargantua" => Box::new(chain_spec::ChainSpec::from_json_bytes(
"gargantua" | "gargantuan" => Box::new(chain_spec::ChainSpec::from_json_bytes(
include_bytes!("../../chainspec/gargantua.json").to_vec(),
)?),
"" | "local" => Box::new(chain_spec::local_testnet_config()),
Expand Down

0 comments on commit c75ed34

Please sign in to comment.