diff --git a/alice_node_config.json b/alice_node_config.json index 1118ba4..51d174d 100644 --- a/alice_node_config.json +++ b/alice_node_config.json @@ -1,16 +1,16 @@ { "networks": { "network_vec": [{ - "url": "https://evm.shibuya.astar.network", - "gateway_contract_address": "337ee83622C8Eb69AE7F8C49431BF982e9dE9036", - "id": 81 + "url": "https://rpc-mumbai.maticvigil.com/", + "gateway_contract_address": "c7BcC4c1f7bA7fF7A618a8B8e1A1c1007cBD5393", + "id": 80001 }, { - "url": "http://127.0.0.1:8545", - "gateway_contract_address": "92660CBfA6F120dD4343AfD4A74A030506dC9Acb", - "id": 26100 + "url": "https://data-seed-prebsc-2-s3.binance.org:8545", + "gateway_contract_address": "c1F13fde5fFDE7B7ae6C95C9190d038A2eEb9e29", + "id": 97 }], - "pair_vec": [[81, 26100], [26100, 81]], + "pair_vec": [[80001, 97], [97, 80001]], "signer_public_key": "020a1091341fe5664bfa1782d5e04779689068c916b04cb365ec3153755684d9a1", "role" : "QP_MINER" } diff --git a/bob_node_config.json b/bob_node_config.json index 8777393..3f84d2c 100644 --- a/bob_node_config.json +++ b/bob_node_config.json @@ -2,12 +2,12 @@ "networks": { "network_vec": [{ "url": "https://rpc-mumbai.maticvigil.com/", - "gateway_contract_address": "fE174DC5FF85Ed8871e4f35d86f1BB32A8461A38", + "gateway_contract_address": "ee8F7BB1ED6CFE3f42C815e56bb3cd47D7393e71", "id": 80001 }, { "url": "http://127.0.0.1:8545", - "gateway_contract_address": "92660CBfA6F120dD4343AfD4A74A030506dC9Acb", + "gateway_contract_address": "660eB2A65026D18705C4B824Cdbfae2203EcAD81", "id": 26100 }], "pair_vec": [[80001, 26100], [26100, 80001]], diff --git a/pallets/quantum-portal/src/contract_client.rs b/pallets/quantum-portal/src/contract_client.rs index 3d1ba3e..3de8a5f 100644 --- a/pallets/quantum-portal/src/contract_client.rs +++ b/pallets/quantum-portal/src/contract_client.rs @@ -102,7 +102,7 @@ impl ContractClient { Ok(address) } - pub fn get_miner_manager_address(&self) -> Result { + pub fn get_miner_manager_address(&self) -> Result<(H160, Vec, Vec), ChainRequestError> { let ledger_manager_address = self.get_ledger_manager_address()?; // no cache, we fetch from the gateway contract @@ -112,18 +112,20 @@ impl ContractClient { let address = ChainUtils::decode_address_response(res.result.as_slice()); log::info!("Miner manager address is : {:?}", address); - let signature = b"VERSION"; + let signature = b"VERSION()"; let res: Box = self.call(signature, &[], Some(address))?; - log::info!("Miner manager version is : {:?}", &res.result.as_slice()); + let version = &res.result.as_slice(); + log::info!("Miner manager version is : {:?}", version); - let signature = b"NAME"; + let signature = b"NAME()"; let res: Box = self.call(signature, &[], Some(address))?; - log::info!("Miner manager name is : {:?}", &res.result.as_slice()); + let name = &res.result.as_slice(); + log::info!("Miner manager name is : {:?}", name); - Ok(address) + Ok((address, version.to_vec(), name.to_vec())) } - pub fn get_authority_manager_address(&self) -> Result { + pub fn get_authority_manager_address(&self) -> Result<(H160, Vec, Vec), ChainRequestError> { let ledger_manager_address = self.get_ledger_manager_address()?; // no cache, we fetch from the gateway contract @@ -133,18 +135,20 @@ impl ContractClient { let address = ChainUtils::decode_address_response(res.result.as_slice()); log::info!("Authority manager address is : {:?}", address); - let signature = b"VERSION"; + let signature = b"VERSION()"; let res: Box = self.call(signature, &[], Some(address))?; + let version = &res.result.as_slice(); log::info!( "Authority manager version is : {:?}", - &res.result.as_slice() + version ); - let signature = b"NAME"; + let signature = b"NAME()"; let res: Box = self.call(signature, &[], Some(address))?; - log::info!("Authority manager name is : {:?}", &res.result.as_slice()); + let name = &res.result.as_slice(); + log::info!("Authority manager name is : {:?}", name); - Ok(address) + Ok((address, version.to_vec(), name.to_vec())) } pub fn call( @@ -211,6 +215,7 @@ impl ContractClient { from: Address, // encoded_bytes: Vec, signing: &ContractClientSignature, + recipient_address: Address, ) -> Result { let encoded_bytes = encoder::encode_function_u8(method_signature, inputs); let encoded_bytes_0x = ChainUtils::bytes_to_hex(encoded_bytes.as_slice()); @@ -222,7 +227,7 @@ impl ContractClient { Some(v) => v, }; let gas_limit_val = match gas_limit { - None => self.estimate_gas(encoded_bytes_slice.as_slice(), &value, from)?, + None => self.estimate_gas(encoded_bytes_slice.as_slice(), &value, from, recipient_address)?, Some(v) => v, }; let gas_price_val = match gas_price { @@ -236,7 +241,7 @@ impl ContractClient { nonce: nonce_val, gas_price: gas_price_val, gas_limit: gas_limit_val, - action: TransactionAction::Call(self.gateway_contract_address), + action: TransactionAction::Call(recipient_address), value, input: encoded_bytes, signature: ChainUtils::empty_signature(), @@ -296,6 +301,7 @@ impl ContractClient { encoded: &[u8], value: &U256, from: Address, + recipient_address: Address, ) -> Result { let call_json = JsonSer::new() .start() @@ -307,7 +313,7 @@ impl ContractClient { .string( "to", str::from_utf8( - ChainUtils::address_to_hex(self.gateway_contract_address).as_slice(), + ChainUtils::address_to_hex(recipient_address).as_slice(), ) .unwrap(), ) diff --git a/pallets/quantum-portal/src/eip_712_utils.rs b/pallets/quantum-portal/src/eip_712_utils.rs index 8e394a6..9418fde 100644 --- a/pallets/quantum-portal/src/eip_712_utils.rs +++ b/pallets/quantum-portal/src/eip_712_utils.rs @@ -1,6 +1,7 @@ use crate::chain_utils::ChainUtils; use ethabi_nostd::{encoder, Token, H256, U256}; //vec::{Vec}; use sp_std::prelude::*; +use ethabi_nostd::Address; pub struct EIP712Utils; @@ -10,7 +11,7 @@ impl EIP712Utils { contract_name: &[u8], contract_version: &[u8], chain_id: u64, - contract_address: &[u8], + contract_address: Address, ) -> H256 { let type_hash = ChainUtils::keccack( b"EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)", @@ -23,7 +24,7 @@ impl EIP712Utils { Token::FixedBytes(Vec::from(hashed_name.as_bytes())), Token::FixedBytes(Vec::from(hashed_version.as_bytes())), Token::Uint(U256::from(chain_id)), - Token::Address(ChainUtils::hex_to_address(contract_address)), + Token::Address(contract_address), ]); encoded_domain_seperator diff --git a/pallets/quantum-portal/src/quantum_portal_client.rs b/pallets/quantum-portal/src/quantum_portal_client.rs index e667b4f..a489b64 100644 --- a/pallets/quantum-portal/src/quantum_portal_client.rs +++ b/pallets/quantum-portal/src/quantum_portal_client.rs @@ -314,15 +314,18 @@ impl QuantumPortalClient { Token::Bytes(multi_sig), ]; + let recipient_address = self.contract.get_ledger_manager_address()?; + let res = self.contract.send( method_signature, &inputs, None, //Some(U256::from(1000000 as u64)), // None, - None, // Some(U256::from(10000000000 as u64)), // None, + None, //Some(U256::from(10000000000 as u64)), // None, U256::zero(), None, self.signer.from, &self.signer, + recipient_address )?; Ok(res) } @@ -341,16 +344,16 @@ impl QuantumPortalClient { salt: Token, expiry: Token, ) -> Result, TransactionCreationError> { - let verifying_contract_address = &self + let (verifying_contract_address, verifying_contract_version, verifying_contract_name) = &self .contract .get_authority_manager_address() .map_err(|_| TransactionCreationError::CannotFindContractAddress)?; // Generate the domain seperator hash, the hash is generated from the given arguments let domain_seperator_hash = EIP712Utils::generate_eip_712_domain_seperator_hash( - &ChainUtils::address_to_hex(*verifying_contract_address), // ContractName - &ChainUtils::address_to_hex(*verifying_contract_address), // ContractVersion + verifying_contract_name, // ContractName + verifying_contract_version, // ContractVersion self.contract.chain_id, // ChainId - &ChainUtils::address_to_hex(*verifying_contract_address), // VerifyingAddress + *verifying_contract_address, // VerifyingAddress ); log::info!("domain_seperator_hash {:?}", domain_seperator_hash); @@ -433,16 +436,16 @@ impl QuantumPortalClient { ) -> ChainRequestResult { let method_signature = b"mineRemoteBlock(uint64,uint64,(uint64,address,address,address,address,uint256,bytes,uint256)[],bytes32,uint64,bytes)"; - // set a random salt - let (random_hash, _) = T::PalletRandomness::random_seed(); - let salt = Token::FixedBytes(Vec::from(random_hash.as_ref())); - // set timestamp 1hr from now let current_timestamp = source_block.timestamp; - let expiry_buffer = core::time::Duration::from_secs(3600u64); + let expiry_buffer = core::time::Duration::from_secs(259200u64); let expiry_time = current_timestamp.saturating_add(expiry_buffer.as_secs()); let expiry = Token::Uint(U256::from(expiry_time)); + // set a random salt + let (random_hash, _) = T::PalletRandomness::random_seed(); + let salt = Token::FixedBytes(Vec::from(random_hash.as_ref())); + let tx_vec: Vec = txs .iter() .map(|t| { @@ -473,6 +476,8 @@ impl QuantumPortalClient { .unwrap() ); + let recipient_address = self.contract.get_ledger_manager_address()?; + let res = self.contract.send( method_signature, &[ @@ -483,12 +488,13 @@ impl QuantumPortalClient { expiry, Token::Bytes(multi_sig), ], - None, // Some(U256::from(1000000 as u32)), // None, - None, // Some(U256::from(60000000000 as u64)), // None, + None, //Some(U256::from(1000000 as u32)), // None, + None, //Some(U256::from(60000000000 as u64)), // None, U256::zero(), None, self.signer.from, &self.signer, + recipient_address )?; Ok(res) } @@ -506,17 +512,17 @@ impl QuantumPortalClient { salt: Token, expiry: Token, ) -> Result, TransactionCreationError> { - let verifying_contract_address = &self + let (verifying_contract_address, verifying_contract_version, verifying_contract_name) = &self .contract .get_miner_manager_address() .map_err(|_| TransactionCreationError::CannotFindContractAddress)?; // Generate the domain seperator hash, the hash is generated from the given arguments let domain_seperator_hash = EIP712Utils::generate_eip_712_domain_seperator_hash( - &ChainUtils::address_to_hex(*verifying_contract_address), // ContractName - &ChainUtils::address_to_hex(*verifying_contract_address), // ContractVersion - self.contract.chain_id, // ChainId - &ChainUtils::address_to_hex(*verifying_contract_address), // VerifyingAddress + b"FERRUM_QUANTUM_PORTAL_MINER_MGR", // ContractName + b"000.010", // ContractVersion + self.contract.chain_id, // ChainId + *verifying_contract_address, // VerifyingAddress ); log::info!("domain_seperator_hash {:?}", domain_seperator_hash); @@ -627,7 +633,7 @@ impl QuantumPortalClient { return Err(ChainRequestError::RemoteBlockAlreadyMined); } log::info!("Getting source block?"); - let source_block = remote_client.local_block_by_nonce(local_chain, last_block.nonce)?; + let source_block = remote_client.local_block_by_nonce(local_chain, last_mined_block.nonce.saturating_add(1))?; let default_qp_transaction = QpTransaction::default(); log::info!( "Source block is GOT\n{:?}\n{:?}", diff --git a/scripts/start-local-testnet.sh b/scripts/start-local-testnet.sh index 69f1f6c..62ae95e 100755 --- a/scripts/start-local-testnet.sh +++ b/scripts/start-local-testnet.sh @@ -1,12 +1,12 @@ # # remove any existing data from chain -# rm -rf ./chain +rm -rf ./chain # # generate chain spec -# ./target/release/ferrum-network build-spec --disable-default-bootnode > ferrum-local-testnet.json +./target/release/ferrum-network build-spec --disable-default-bootnode > ferrum-local-testnet.json # # insert the signing keys for alice -# ./target/release/ferrum-network key insert --key-type ofsg --scheme ecdsa --base-path ./chain/alice --chain ferrum-local-testnet.json --suri //Alice +./target/release/ferrum-network key insert --key-type ofsg --scheme ecdsa --base-path ./chain/alice --chain ferrum-local-testnet.json --suri //Alice # # insert the signing keys for bob # ./target/release/ferrum-network key insert --key-type ofsg --scheme ecdsa --base-path ./chain/bob --chain ferrum-local-testnet.json --suri //Bob