From ea0e936ac43519b190f373d9d9e5c46595018c71 Mon Sep 17 00:00:00 2001 From: Akihito Nakano Date: Wed, 22 Jul 2020 09:34:57 +0000 Subject: [PATCH] Small improvement: encapsulate a public field (#1362) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Issue Addressed This PR makes the `Eth1Chain::use_dummy_backend` field private. I believe this could be good to ensure the consistency of a Eth1Chain instance. 💡 --- beacon_node/beacon_chain/src/builder.rs | 5 +---- beacon_node/beacon_chain/src/eth1_chain.rs | 9 ++++++++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/beacon_node/beacon_chain/src/builder.rs b/beacon_node/beacon_chain/src/builder.rs index edfb4a8243..9ebe1f0bf6 100644 --- a/beacon_node/beacon_chain/src/builder.rs +++ b/beacon_node/beacon_chain/src/builder.rs @@ -586,10 +586,7 @@ where let backend = CachingEth1Backend::new(Eth1Config::default(), log.clone(), self.spec.clone()); - let mut eth1_chain = Eth1Chain::new(backend); - eth1_chain.use_dummy_backend = true; - - self.eth1_chain = Some(eth1_chain); + self.eth1_chain = Some(Eth1Chain::new_dummy(backend)); Ok(self) } diff --git a/beacon_node/beacon_chain/src/eth1_chain.rs b/beacon_node/beacon_chain/src/eth1_chain.rs index 86bbc90780..b9af5027c4 100644 --- a/beacon_node/beacon_chain/src/eth1_chain.rs +++ b/beacon_node/beacon_chain/src/eth1_chain.rs @@ -82,7 +82,7 @@ where backend: T, /// When `true`, the backend will be ignored and dummy data from the 2019 Canada interop method /// will be used instead. - pub use_dummy_backend: bool, + use_dummy_backend: bool, _phantom: PhantomData, } @@ -99,6 +99,13 @@ where } } + pub fn new_dummy(backend: T) -> Self { + Self { + use_dummy_backend: true, + ..Self::new(backend) + } + } + /// Returns the `Eth1Data` that should be included in a block being produced for the given /// `state`. pub fn eth1_data_for_block_production(