Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add prom metrics for last mined block #3791

Merged
merged 4 commits into from
Jul 28, 2023
Merged

Add prom metrics for last mined block #3791

merged 4 commits into from
Jul 28, 2023

Conversation

pavitthrap
Copy link
Contributor

Description

Adds prom metrics for last mined block.

This PR also includes a fix to a bug introduced in Epoch 2.1, related to segwit addresses. Essentially, there was a mismatch between the representation of the miner address stored for prometheus and the representation of the miner address within the decoded LeaderBlockCommitOp.
To fix this, it was necessary to update the representation of the miner address within the prometheus related code.

Applicable issues

@codecov
Copy link

codecov bot commented Jul 13, 2023

Codecov Report

Merging #3791 (09ec5d3) into develop (8c62f91) will decrease coverage by 0.01%.
Report is 4 commits behind head on develop.
The diff coverage is 0.00%.

@@             Coverage Diff             @@
##           develop    #3791      +/-   ##
===========================================
- Coverage     0.18%    0.18%   -0.01%     
===========================================
  Files          301      306       +5     
  Lines       278555   278640      +85     
===========================================
  Hits           512      512              
- Misses      278043   278128      +85     
Files Changed Coverage Δ
pox-locking/src/events.rs 0.00% <0.00%> (ø)
pox-locking/src/lib.rs 0.00% <0.00%> (ø)
pox-locking/src/pox_1.rs 0.00% <0.00%> (ø)
pox-locking/src/pox_2.rs 0.00% <0.00%> (ø)
pox-locking/src/pox_3.rs 0.00% <0.00%> (ø)
src/chainstate/stacks/db/accounts.rs 0.00% <ø> (ø)
src/chainstate/stacks/miner.rs 0.00% <0.00%> (ø)
src/clarity_vm/special.rs 0.00% <0.00%> (ø)
src/monitoring/mod.rs 0.00% <0.00%> (ø)
...-node/src/burnchains/bitcoin_regtest_controller.rs 0.00% <0.00%> (ø)
... and 3 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@@ -4182,6 +4174,17 @@ impl StacksNode {
globals.set_initial_leader_key_registration_state(leader_key_registration_state);

let relayer_thread = RelayerThread::new(runloop, local_peer.clone(), relayer);

let public_key = keychain.get_pub_key();
let miner_addr = relayer_thread.bitcoin_controller.get_miner_address(StacksEpochId::Epoch21, &public_key);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the right epoch to use? Is there a way to use whatever the node's current epoch is?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I discussed this with @kantai, and he felt that hard-coding this parameter to Epoch21 made sense - want to chime in?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, so the issue here is that the "miner address" in the bitcoin controller behaves somewhat surprisingly with epochs and segwit configuration:

        if self.config.miner.segwit && epoch_id >= StacksEpochId::Epoch21 {
            let hash160 = Hash160::from_data(&public_key.to_bytes_compressed());
            BitcoinAddress::from_bytes_segwit_p2wpkh(network_id, &hash160.0)
                .expect("Public key incorrect")
        } else {
            let hash160 = Hash160::from_data(&public_key.to_bytes());
            BitcoinAddress::from_bytes_legacy(
                network_id,
                LegacyBitcoinAddressType::PublicKeyHash,
                &hash160.0,
            )
            .expect("Public key incorrect")
        }

So, if segwit = true, then the miner mines from two different bitcoin addresses if the epoch boundary is crossed.

As it pertains to the mining monitoring (which is where this variable is used), the monitoring thread assumes a globally static miner address. That's not actually the case, unfortunately, so this is kind of a hack -- if the miner config setting opts into segwit mining, the monitoring code always expects to be watching for a segwit mining address, even if epoch-2.1 hasn't started yet.

I think this is okay in the monitoring code, but I do think it's bad code hygiene, and should have a comment reflecting this logic (and be separated away from the rest of the spawn code into its own method). I think that really the get_miner_address behavior should be changed so that it no longer accepts an epoch parameter, but I understand that probably impacts the integration tests (I cannot imagine a real world miner at any point depended on this code -- it would have required preemptively funding the segwit address for the switch over).

Copy link
Member

@jcnelson jcnelson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Just a couple of minor things.

@pavitthrap pavitthrap requested a review from obycode July 17, 2023 23:28
Copy link
Member

@kantai kantai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, but I think you should add a comment to the changes at around lines 4180 in the neon_node and also just move them into a private function like set_monitoring_miner_address() so that its clear that the calculations there are only used by the monitoring code.

@pavitthrap pavitthrap requested a review from kantai July 19, 2023 18:21
@wileyj
Copy link
Contributor

wileyj commented Jul 19, 2023

ping @kantai @obycode

@kantai kantai self-assigned this Jul 28, 2023
@kantai kantai merged commit 1d2c57b into develop Jul 28, 2023
2 checks passed
@kantai kantai deleted the prom/mined-block-stat branch July 28, 2023 18:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

None yet

4 participants