Add graffiti cli flag to the validator client. (#1425)

## Issue Addressed

#1419

## Proposed Changes

Creates a `--graffiti` cli flag in the validator client. If the flag is set, it overrides graffiti in the beacon node. 

## Additional Info
This commit is contained in:
realbigsean
2020-08-11 02:16:29 +00:00
parent 95b55d7170
commit ec84183e05
9 changed files with 125 additions and 21 deletions

View File

@@ -1564,12 +1564,13 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
&self,
randao_reveal: Signature,
slot: Slot,
validator_graffiti: Option<Graffiti>,
) -> Result<BeaconBlockAndState<T::EthSpec>, BlockProductionError> {
let state = self
.state_at_slot(slot - 1, StateSkipConfig::WithStateRoots)
.map_err(|_| BlockProductionError::UnableToProduceAtSlot(slot))?;
self.produce_block_on_state(state, slot, randao_reveal)
self.produce_block_on_state(state, slot, randao_reveal, validator_graffiti)
}
/// Produce a block for some `slot` upon the given `state`.
@@ -1585,6 +1586,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
mut state: BeaconState<T::EthSpec>,
produce_at_slot: Slot,
randao_reveal: Signature,
validator_graffiti: Option<Graffiti>,
) -> Result<BeaconBlockAndState<T::EthSpec>, BlockProductionError> {
metrics::inc_counter(&metrics::BLOCK_PRODUCTION_REQUESTS);
let timer = metrics::start_timer(&metrics::BLOCK_PRODUCTION_TIMES);
@@ -1652,6 +1654,12 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
}
}
// Override the beacon node's graffiti with graffiti from the validator, if present.
let graffiti = match validator_graffiti {
Some(graffiti) => graffiti,
None => self.graffiti,
};
let mut block = SignedBeaconBlock {
message: BeaconBlock {
slot: state.slot,
@@ -1661,7 +1669,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
body: BeaconBlockBody {
randao_reveal,
eth1_data,
graffiti: self.graffiti,
graffiti,
proposer_slashings: proposer_slashings.into(),
attester_slashings: attester_slashings.into(),
attestations: self

View File

@@ -520,7 +520,7 @@ where
let (block, state) = self
.chain
.produce_block_on_state(state, slot, randao_reveal)
.produce_block_on_state(state, slot, randao_reveal, None)
.expect("should produce block");
let signed_block = block.sign(sk, &state.fork, state.genesis_validators_root, &self.spec);