Merge pull request #505 from kinode-dao/bp/fakenet-fix

fakenet fixes
This commit is contained in:
bitful-pannul 2024-08-28 13:23:24 +03:00 committed by GitHub
commit a4a643a6f2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 71 additions and 47 deletions

View File

@ -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

View File

@ -156,6 +156,7 @@ fn main(our: Address, mut state: State) -> anyhow::Result<()> {
// set a timer tick so any pending logs will be processed
timer::set_timer(DELAY_MS, None);
println!("done syncing old logs.");
handle_pending_notes(&mut state, &mut pending_notes)?;
loop {
let Ok(message) = await_message() else {
@ -435,15 +436,20 @@ fn handle_log(
if !kimap::valid_note(&note) {
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::<KnsError>() {
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 => {

View File

@ -58,38 +58,7 @@ pub async fn mint_local(
let provider: RootProvider<PubSubFrontend> = 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,79 @@ 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<u8> = 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?;
// 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(())
}