From 09d537e9b03d5c529435c0d3dead415fa9f03220 Mon Sep 17 00:00:00 2001 From: bitful-pannul Date: Mon, 26 Aug 2024 16:23:06 +0300 Subject: [PATCH 1/8] fakenet: reduce to 1 tx, wait for receipt --- kinode/src/fakenet.rs | 69 ++++++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 37 deletions(-) diff --git a/kinode/src/fakenet.rs b/kinode/src/fakenet.rs index 59a01641b..0240eb297 100644 --- a/kinode/src/fakenet.rs +++ b/kinode/src/fakenet.rs @@ -58,38 +58,7 @@ pub async fn mint_local( let provider: RootProvider = ProviderBuilder::default().on_ws(ws).await?; - // interesting, even if we have a minted name, this does not explicitly fail. - // also note, fake.dev.os seems to currently work, need to gate dots from names? - let mint_call = mintCall { - who: wallet_address, - label: Bytes::from(label.as_bytes().to_vec()), - initialization: vec![].into(), - erc721Data: vec![].into(), - implementation: Address::from_str(KINO_ACCOUNT_IMPL).unwrap(), - } - .abi_encode(); - - let nonce = provider.get_transaction_count(wallet_address).await?; - - let tx = TransactionRequest::default() - .to(minter) - .input(TransactionInput::new(mint_call.into())) - .nonce(nonce) - .with_chain_id(31337) - .with_gas_limit(12_000_00) - .with_max_priority_fee_per_gas(200_000_000_000) - .with_max_fee_per_gas(300_000_000_000); - - // Build the transaction using the `EthereumSigner` with the provided signer. - let tx_envelope = tx.build(&wallet).await?; - - // Encode the transaction using EIP-2718 encoding. - let tx_encoded = tx_envelope.encoded_2718(); - - // Send the raw transaction and retrieve the transaction receipt. - let _tx_hash = provider.send_raw_transaction(&tx_encoded).await?; - - // get tba to set KNS records + // get tba to see if name is already registered let namehash: [u8; 32] = keygen::namehash(name); let get_call = getCall { @@ -149,30 +118,56 @@ pub async fn mint_local( }, ]; + let is_reset = tba != Address::default(); + let multicall = aggregateCall { calls: multicalls }.abi_encode(); - let execute_call = executeCall { + let execute_call: Vec = executeCall { to: multicall_address, value: U256::from(0), // free mint data: multicall.into(), - operation: 1, // ? + operation: 1, } .abi_encode(); + let (input_bytes, to) = if is_reset { + // name is already registered, multicall reset it + (execute_call, tba) + } else { + // name is not registered, mint it with multicall in initialization param + ( + mintCall { + who: wallet_address, + label: Bytes::from(label.as_bytes().to_vec()), + initialization: execute_call.into(), + erc721Data: vec![].into(), + implementation: Address::from_str(KINO_ACCOUNT_IMPL).unwrap(), + } + .abi_encode(), + minter, + ) + }; + let nonce = provider.get_transaction_count(wallet_address).await?; let tx = TransactionRequest::default() - .to(tba) - .input(TransactionInput::new(execute_call.into())) + .to(to) + .input(TransactionInput::new(input_bytes.into())) .nonce(nonce) .with_chain_id(31337) .with_gas_limit(12_000_00) .with_max_priority_fee_per_gas(200_000_000_000) .with_max_fee_per_gas(300_000_000_000); + // Build the transaction using the `EthereumSigner` with the provided signer. let tx_envelope = tx.build(&wallet).await?; + + // Encode the transaction using EIP-2718 encoding. let tx_encoded = tx_envelope.encoded_2718(); - let _tx_hash = provider.send_raw_transaction(&tx_encoded).await?; + + // Send the raw transaction and retrieve the transaction receipt. + let tx_hash = provider.send_raw_transaction(&tx_encoded).await?; + let _receipt = tx_hash.get_receipt().await?; Ok(()) } From be6b9321650a50f32592c42be46f3d733500fc8b Mon Sep 17 00:00:00 2001 From: bitful-pannul Date: Mon, 26 Aug 2024 16:23:23 +0300 Subject: [PATCH 2/8] kns_indexer: optimistically handle notes --- .../kns_indexer/kns_indexer/src/lib.rs | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/kinode/packages/kns_indexer/kns_indexer/src/lib.rs b/kinode/packages/kns_indexer/kns_indexer/src/lib.rs index 4b93a38b3..9cfffb1e9 100644 --- a/kinode/packages/kns_indexer/kns_indexer/src/lib.rs +++ b/kinode/packages/kns_indexer/kns_indexer/src/lib.rs @@ -433,15 +433,22 @@ fn handle_log( if !kimap::valid_note(¬e) { return Err(anyhow::anyhow!("skipping invalid note: {note}")); } - if let Some(block_number) = log.block_number { - print_to_terminal( - 1, - &format!("adding note to pending_notes for block {block_number}"), - ); - pending_notes - .entry(block_number) - .or_default() - .push((decoded, 0)); + // handle note: if it precedes parent mint event, add it to pending_notes + if let Err(e) = handle_note(state, &decoded) { + if let Some(KnsError::NoParentError) = e.downcast_ref::() { + if let Some(KnsError::NoParentError) = e.downcast_ref::() { + if let Some(block_number) = log.block_number { + print_to_terminal( + 1, + &format!("adding note to pending_notes for block {block_number}"), + ); + pending_notes + .entry(block_number) + .or_default() + .push((decoded, 0)); + } + } + } } } _log => { From 6ce5f25b3bd1c37b3e4c4616134173a7571353dd Mon Sep 17 00:00:00 2001 From: bitful-pannul Date: Mon, 26 Aug 2024 16:35:39 +0300 Subject: [PATCH 3/8] app_store: fix fakenet --- kinode/packages/app_store/chain/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kinode/packages/app_store/chain/src/lib.rs b/kinode/packages/app_store/chain/src/lib.rs index 0d596c543..88ea3e5d6 100644 --- a/kinode/packages/app_store/chain/src/lib.rs +++ b/kinode/packages/app_store/chain/src/lib.rs @@ -38,7 +38,7 @@ const CHAIN_TIMEOUT: u64 = 60; // 60s #[cfg(not(feature = "simulation-mode"))] const KIMAP_ADDRESS: &'static str = kimap::KIMAP_ADDRESS; // optimism #[cfg(feature = "simulation-mode")] -const KIMAP_ADDRESS: &str = "0xcA92476B2483aBD5D82AEBF0b56701Bb2e9be658"; +const KIMAP_ADDRESS: &str = "0xEce71a05B36CA55B895427cD9a440eEF7Cf3669D"; const DELAY_MS: u64 = 1_000; // 1s From 9ece3e86f88b9eed87ce4a2e4b6d83fa624b8be6 Mon Sep 17 00:00:00 2001 From: bitful-pannul Date: Mon, 26 Aug 2024 20:27:07 +0300 Subject: [PATCH 4/8] kns_indexer: typo --- .../kns_indexer/kns_indexer/src/lib.rs | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/kinode/packages/kns_indexer/kns_indexer/src/lib.rs b/kinode/packages/kns_indexer/kns_indexer/src/lib.rs index 9cfffb1e9..4716147c0 100644 --- a/kinode/packages/kns_indexer/kns_indexer/src/lib.rs +++ b/kinode/packages/kns_indexer/kns_indexer/src/lib.rs @@ -436,17 +436,15 @@ fn handle_log( // handle note: if it precedes parent mint event, add it to pending_notes if let Err(e) = handle_note(state, &decoded) { if let Some(KnsError::NoParentError) = e.downcast_ref::() { - if let Some(KnsError::NoParentError) = e.downcast_ref::() { - if let Some(block_number) = log.block_number { - print_to_terminal( - 1, - &format!("adding note to pending_notes for block {block_number}"), - ); - pending_notes - .entry(block_number) - .or_default() - .push((decoded, 0)); - } + if let Some(block_number) = log.block_number { + print_to_terminal( + 1, + &format!("adding note to pending_notes for block {block_number}"), + ); + pending_notes + .entry(block_number) + .or_default() + .push((decoded, 0)); } } } From 4f313af7c3da8d2106574d2ffba14960872ff872 Mon Sep 17 00:00:00 2001 From: bitful-pannul Date: Mon, 26 Aug 2024 23:05:55 +0300 Subject: [PATCH 5/8] fakenet: test not waiting for receipt upon registration --- kinode/src/fakenet.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/kinode/src/fakenet.rs b/kinode/src/fakenet.rs index 0240eb297..a2d9d60fb 100644 --- a/kinode/src/fakenet.rs +++ b/kinode/src/fakenet.rs @@ -166,8 +166,7 @@ pub async fn mint_local( let tx_encoded = tx_envelope.encoded_2718(); // Send the raw transaction and retrieve the transaction receipt. - let tx_hash = provider.send_raw_transaction(&tx_encoded).await?; - let _receipt = tx_hash.get_receipt().await?; + let _tx_hash = provider.send_raw_transaction(&tx_encoded).await?; Ok(()) } From 83ea1be8ba685e7137e978b1ecfd2eb31ca8d967 Mon Sep 17 00:00:00 2001 From: bitful-pannul Date: Tue, 27 Aug 2024 00:32:42 +0300 Subject: [PATCH 6/8] kns_indexer: handle initial pending notes after boot --- kinode/packages/kns_indexer/kns_indexer/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/kinode/packages/kns_indexer/kns_indexer/src/lib.rs b/kinode/packages/kns_indexer/kns_indexer/src/lib.rs index 4716147c0..b41d4a2da 100644 --- a/kinode/packages/kns_indexer/kns_indexer/src/lib.rs +++ b/kinode/packages/kns_indexer/kns_indexer/src/lib.rs @@ -154,6 +154,7 @@ fn main(our: Address, mut state: State) -> anyhow::Result<()> { &mut pending_notes, ); println!("done syncing old logs."); + handle_pending_notes(&mut state, &mut pending_notes)?; loop { let Ok(message) = await_message() else { From fd04762ffb463e962defac85e85fe3f723018fc4 Mon Sep 17 00:00:00 2001 From: bitful-pannul Date: Tue, 27 Aug 2024 18:09:31 +0300 Subject: [PATCH 7/8] fakenet: wait for receipt before booting --- kinode/src/fakenet.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kinode/src/fakenet.rs b/kinode/src/fakenet.rs index a2d9d60fb..0240eb297 100644 --- a/kinode/src/fakenet.rs +++ b/kinode/src/fakenet.rs @@ -166,7 +166,8 @@ pub async fn mint_local( let tx_encoded = tx_envelope.encoded_2718(); // Send the raw transaction and retrieve the transaction receipt. - let _tx_hash = provider.send_raw_transaction(&tx_encoded).await?; + let tx_hash = provider.send_raw_transaction(&tx_encoded).await?; + let _receipt = tx_hash.get_receipt().await?; Ok(()) } From d75c67c4340d7012996331b5d17cb027ce538d03 Mon Sep 17 00:00:00 2001 From: bitful-pannul Date: Tue, 27 Aug 2024 23:16:05 +0300 Subject: [PATCH 8/8] fakenet: add an extra template tx (hacky) after registering --- kinode/src/fakenet.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/kinode/src/fakenet.rs b/kinode/src/fakenet.rs index 0240eb297..031b56d5c 100644 --- a/kinode/src/fakenet.rs +++ b/kinode/src/fakenet.rs @@ -169,6 +169,29 @@ pub async fn mint_local( let tx_hash = provider.send_raw_transaction(&tx_encoded).await?; let _receipt = tx_hash.get_receipt().await?; + // send a small amount of ETH to the zero address + // this is a workaround to get anvil to mine a block after our registration tx + // instead of doing block-time 1s or similar, which leads to runaway mem-usage. + let zero_address = Address::default(); + let small_amount = U256::from(10); // 10 wei (0.00000001 ETH) + + let nonce = provider.get_transaction_count(wallet_address).await?; + + let small_tx = TransactionRequest::default() + .to(zero_address) + .value(small_amount) + .nonce(nonce) + .with_chain_id(31337) + .with_gas_limit(21_000) + .with_max_priority_fee_per_gas(200_000_000_000) + .with_max_fee_per_gas(300_000_000_000); + + let small_tx_envelope = small_tx.build(&wallet).await?; + let small_tx_encoded = small_tx_envelope.encoded_2718(); + + let small_tx_hash = provider.send_raw_transaction(&small_tx_encoded).await?; + let _small_receipt = small_tx_hash.get_receipt().await?; + Ok(()) }