foundry icon indicating copy to clipboard operation
foundry copied to clipboard

feat(anvil): add anvil_getIntervalMining method

Open feynman-x opened this issue 1 year ago • 1 comments

Motivation

Closes https://github.com/foundry-rs/foundry/issues/8813

Solution

feynman-x avatar Oct 11 '24 01:10 feynman-x

@mattsse Thanks! I’ve submitted new code commit and provided responses for your suggestions. Please take a look and let me know if there’s anything else.

feynman-x avatar Oct 12 '24 06:10 feynman-x

@feynman-x I think this PR could be simplified, consider that we already have anvil_set_auto_mine/anvil_get_auto_mine which use miner.is_auto_mine() https://github.com/foundry-rs/foundry/blob/6b0c27ed4ccfdb5a4805e9f53d487cca51c5e116/crates/anvil/src/eth/miner.rs#L61-L65

We also have anvil_set_interval_mining (but no anvil_get_interval_mining counterpart) and is_interval fn which is currently not used at all https://github.com/foundry-rs/foundry/blob/6b0c27ed4ccfdb5a4805e9f53d487cca51c5e116/crates/anvil/src/eth/miner.rs#L67-L70

I propose to change this to

    pub fn get_interval(&self) -> Option<u64> {
        if let MiningMode::FixedBlockTime(mm) = self.mode.read().deref() {
            return Some(mm.interval.period().as_secs())
        }
        None
    }

and add the get interval mine handler

    EthRequest::GetIntervalMine(()) => self.anvil_get_interval_mine().to_rpc_result(),
...
    pub fn anvil_get_interval_mine(&self) -> Result<Option<u64> {
        node_info!("anvil_getIntervalMine");
        Ok(self.miner.get_interval())
    }

so if interval mining not set this will return

{"jsonrpc":"2.0","id":1,"result":null}

else the mining interval

{"jsonrpc":"2.0","id":1,"result":12}

Please let me know if you have bandwidth to work on the change, otherwise I could accommodate them. Thank you!

grandizzy avatar Nov 01 '24 11:11 grandizzy

@mattsse Thanks for your suggestion. I will complete the modifications this week.

feynman-x avatar Nov 04 '24 14:11 feynman-x

I've created a new PR, so close this one. See PR https://github.com/foundry-rs/foundry/pull/9290 for more details.

feynman-x avatar Nov 09 '24 09:11 feynman-x