mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-14 10:22:38 +00:00
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:
@@ -1,4 +1,6 @@
|
||||
use crate::helpers::{check_content_type_for_json, publish_beacon_block_to_network};
|
||||
use crate::helpers::{
|
||||
check_content_type_for_json, parse_hex_ssz_bytes, publish_beacon_block_to_network,
|
||||
};
|
||||
use crate::response_builder::ResponseBuilder;
|
||||
use crate::{ApiError, ApiResult, NetworkChannel, UrlQuery};
|
||||
use beacon_chain::{
|
||||
@@ -288,8 +290,14 @@ pub fn get_new_beacon_block<T: BeaconChainTypes>(
|
||||
let slot = query.slot()?;
|
||||
let randao_reveal = query.randao_reveal()?;
|
||||
|
||||
let validator_graffiti = if let Some((_key, value)) = query.first_of_opt(&["graffiti"]) {
|
||||
Some(parse_hex_ssz_bytes(&value)?)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let (new_block, _state) = beacon_chain
|
||||
.produce_block(randao_reveal, slot)
|
||||
.produce_block(randao_reveal, slot, validator_graffiti)
|
||||
.map_err(|e| {
|
||||
error!(
|
||||
log,
|
||||
|
||||
@@ -460,7 +460,7 @@ fn validator_block_post() {
|
||||
remote_node
|
||||
.http
|
||||
.validator()
|
||||
.produce_block(slot, randao_reveal),
|
||||
.produce_block(slot, randao_reveal, None),
|
||||
)
|
||||
.expect("should fetch block from http api");
|
||||
|
||||
@@ -547,7 +547,7 @@ fn validator_block_get() {
|
||||
remote_node
|
||||
.http
|
||||
.validator()
|
||||
.produce_block(slot, randao_reveal.clone()),
|
||||
.produce_block(slot, randao_reveal.clone(), None),
|
||||
)
|
||||
.expect("should fetch block from http api");
|
||||
|
||||
@@ -555,7 +555,50 @@ fn validator_block_get() {
|
||||
.client
|
||||
.beacon_chain()
|
||||
.expect("client should have beacon chain")
|
||||
.produce_block(randao_reveal, slot)
|
||||
.produce_block(randao_reveal, slot, None)
|
||||
.expect("should produce block");
|
||||
|
||||
assert_eq!(
|
||||
block, expected_block,
|
||||
"the block returned from the API should be as expected"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn validator_block_get_with_graffiti() {
|
||||
let mut env = build_env();
|
||||
|
||||
let spec = &E::default_spec();
|
||||
|
||||
let node = build_node(&mut env, testing_client_config());
|
||||
let remote_node = node.remote_node().expect("should produce remote node");
|
||||
|
||||
let beacon_chain = node
|
||||
.client
|
||||
.beacon_chain()
|
||||
.expect("client should have beacon chain");
|
||||
|
||||
let slot = Slot::new(1);
|
||||
let randao_reveal = get_randao_reveal(beacon_chain, slot, spec);
|
||||
|
||||
let block = env
|
||||
.runtime()
|
||||
.block_on(remote_node.http.validator().produce_block(
|
||||
slot,
|
||||
randao_reveal.clone(),
|
||||
Some(*b"test-graffiti-test-graffiti-test"),
|
||||
))
|
||||
.expect("should fetch block from http api");
|
||||
|
||||
let (expected_block, _state) = node
|
||||
.client
|
||||
.beacon_chain()
|
||||
.expect("client should have beacon chain")
|
||||
.produce_block(
|
||||
randao_reveal,
|
||||
slot,
|
||||
Some(*b"test-graffiti-test-graffiti-test"),
|
||||
)
|
||||
.expect("should produce block");
|
||||
|
||||
assert_eq!(
|
||||
|
||||
Reference in New Issue
Block a user