mirror of https://github.com/hyperledger/besu
fix trie by asking peers (#4312)
* fix trie by asking peers Signed-off-by: Karim TAAM <karim.t2am@gmail.com>pull/4362/head
parent
101f5efbdc
commit
c57dcd99d9
@ -0,0 +1,29 @@ |
||||
/* |
||||
* Copyright contributors to Hyperledger Besu |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
package org.hyperledger.besu.ethereum.worldstate; |
||||
|
||||
import org.hyperledger.besu.datatypes.Hash; |
||||
|
||||
import java.util.Optional; |
||||
|
||||
import org.apache.tuweni.bytes.Bytes; |
||||
import org.apache.tuweni.bytes.Bytes32; |
||||
|
||||
public interface PeerTrieNodeFinder { |
||||
|
||||
Optional<Bytes> getAccountStateTrieNode(final Bytes location, final Bytes32 nodeHash); |
||||
|
||||
Optional<Bytes> getAccountStorageTrieNode(Hash accountHash, Bytes location, Bytes32 nodeHash); |
||||
} |
@ -0,0 +1,156 @@ |
||||
/* |
||||
* Copyright contributors to Hyperledger Besu |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
package org.hyperledger.besu.ethereum.eth.sync.worldstate; |
||||
|
||||
import org.hyperledger.besu.datatypes.Hash; |
||||
import org.hyperledger.besu.ethereum.chain.Blockchain; |
||||
import org.hyperledger.besu.ethereum.core.BlockHeader; |
||||
import org.hyperledger.besu.ethereum.eth.manager.EthContext; |
||||
import org.hyperledger.besu.ethereum.eth.manager.snap.RetryingGetTrieNodeFromPeerTask; |
||||
import org.hyperledger.besu.ethereum.eth.manager.task.EthTask; |
||||
import org.hyperledger.besu.ethereum.eth.manager.task.RetryingGetNodeDataFromPeerTask; |
||||
import org.hyperledger.besu.ethereum.trie.CompactEncoding; |
||||
import org.hyperledger.besu.ethereum.worldstate.PeerTrieNodeFinder; |
||||
import org.hyperledger.besu.plugin.services.MetricsSystem; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.HashMap; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
import java.util.Optional; |
||||
import java.util.concurrent.ExecutionException; |
||||
import java.util.concurrent.TimeUnit; |
||||
import java.util.concurrent.TimeoutException; |
||||
|
||||
import com.google.common.cache.Cache; |
||||
import com.google.common.cache.CacheBuilder; |
||||
import org.apache.tuweni.bytes.Bytes; |
||||
import org.apache.tuweni.bytes.Bytes32; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
|
||||
/** This class is used to retrieve missing nodes in the trie by querying the peers */ |
||||
public class WorldStatePeerTrieNodeFinder implements PeerTrieNodeFinder { |
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(WorldStatePeerTrieNodeFinder.class); |
||||
|
||||
private final Cache<Bytes32, Bytes> foundNodes = |
||||
CacheBuilder.newBuilder().maximumSize(10_000).expireAfterWrite(5, TimeUnit.MINUTES).build(); |
||||
|
||||
private static final long TIMEOUT_SECONDS = 1; |
||||
|
||||
final EthContext ethContext; |
||||
final Blockchain blockchain; |
||||
final MetricsSystem metricsSystem; |
||||
|
||||
public WorldStatePeerTrieNodeFinder( |
||||
final EthContext ethContext, final Blockchain blockchain, final MetricsSystem metricsSystem) { |
||||
this.ethContext = ethContext; |
||||
this.blockchain = blockchain; |
||||
this.metricsSystem = metricsSystem; |
||||
} |
||||
|
||||
@Override |
||||
public Optional<Bytes> getAccountStateTrieNode(final Bytes location, final Bytes32 nodeHash) { |
||||
Optional<Bytes> cachedValue = Optional.ofNullable(foundNodes.getIfPresent(nodeHash)); |
||||
if (cachedValue.isPresent()) { |
||||
return cachedValue; |
||||
} |
||||
final Optional<Bytes> response = |
||||
findByGetNodeData(Hash.wrap(nodeHash)) |
||||
.or(() -> findByGetTrieNodeData(Hash.wrap(nodeHash), Optional.empty(), location)); |
||||
response.ifPresent( |
||||
bytes -> { |
||||
LOG.debug( |
||||
"Fixed missing account state trie node for location {} and hash {}", |
||||
location, |
||||
nodeHash); |
||||
foundNodes.put(nodeHash, bytes); |
||||
}); |
||||
return response; |
||||
} |
||||
|
||||
@Override |
||||
public Optional<Bytes> getAccountStorageTrieNode( |
||||
final Hash accountHash, final Bytes location, final Bytes32 nodeHash) { |
||||
Optional<Bytes> cachedValue = Optional.ofNullable(foundNodes.getIfPresent(nodeHash)); |
||||
if (cachedValue.isPresent()) { |
||||
return cachedValue; |
||||
} |
||||
final Optional<Bytes> response = |
||||
findByGetNodeData(Hash.wrap(nodeHash)) |
||||
.or( |
||||
() -> |
||||
findByGetTrieNodeData(Hash.wrap(nodeHash), Optional.of(accountHash), location)); |
||||
response.ifPresent( |
||||
bytes -> { |
||||
LOG.debug( |
||||
"Fixed missing storage state trie node for location {} and hash {}", |
||||
location, |
||||
nodeHash); |
||||
foundNodes.put(nodeHash, bytes); |
||||
}); |
||||
return response; |
||||
} |
||||
|
||||
public Optional<Bytes> findByGetNodeData(final Hash nodeHash) { |
||||
final BlockHeader chainHead = blockchain.getChainHeadHeader(); |
||||
final RetryingGetNodeDataFromPeerTask retryingGetNodeDataFromPeerTask = |
||||
RetryingGetNodeDataFromPeerTask.forHashes( |
||||
ethContext, List.of(nodeHash), chainHead.getNumber(), metricsSystem); |
||||
try { |
||||
final Map<Hash, Bytes> response = |
||||
retryingGetNodeDataFromPeerTask.run().get(TIMEOUT_SECONDS, TimeUnit.SECONDS); |
||||
if (response.containsKey(nodeHash)) { |
||||
LOG.debug("Found node {} with getNodeData request", nodeHash); |
||||
return Optional.of(response.get(nodeHash)); |
||||
} else { |
||||
LOG.debug("Found invalid node {} with getNodeData request", nodeHash); |
||||
} |
||||
} catch (InterruptedException | ExecutionException | TimeoutException e) { |
||||
LOG.debug("Error when trying to find node {} with getNodeData request", nodeHash); |
||||
} |
||||
return Optional.empty(); |
||||
} |
||||
|
||||
public Optional<Bytes> findByGetTrieNodeData( |
||||
final Hash nodeHash, final Optional<Bytes32> accountHash, final Bytes location) { |
||||
final BlockHeader chainHead = blockchain.getChainHeadHeader(); |
||||
final Map<Bytes, List<Bytes>> request = new HashMap<>(); |
||||
if (accountHash.isPresent()) { |
||||
request.put(accountHash.get(), List.of(CompactEncoding.encode(location))); |
||||
} else { |
||||
request.put(CompactEncoding.encode(location), new ArrayList<>()); |
||||
} |
||||
final Bytes path = CompactEncoding.encode(location); |
||||
final EthTask<Map<Bytes, Bytes>> getTrieNodeFromPeerTask = |
||||
RetryingGetTrieNodeFromPeerTask.forTrieNodes(ethContext, request, chainHead, metricsSystem); |
||||
try { |
||||
final Map<Bytes, Bytes> response = |
||||
getTrieNodeFromPeerTask.run().get(TIMEOUT_SECONDS, TimeUnit.SECONDS); |
||||
final Bytes nodeValue = |
||||
response.get(Bytes.concatenate(accountHash.map(Bytes::wrap).orElse(Bytes.EMPTY), path)); |
||||
if (nodeValue != null && Hash.hash(nodeValue).equals(nodeHash)) { |
||||
LOG.debug("Found node {} with getTrieNode request", nodeHash); |
||||
return Optional.of(nodeValue); |
||||
} else { |
||||
LOG.debug("Found invalid node {} with getTrieNode request", nodeHash); |
||||
} |
||||
} catch (InterruptedException | ExecutionException | TimeoutException e) { |
||||
LOG.debug("Error when trying to find node {} with getTrieNode request", nodeHash); |
||||
} |
||||
return Optional.empty(); |
||||
} |
||||
} |
@ -0,0 +1,61 @@ |
||||
/* |
||||
* Copyright contributors to Hyperledger Besu |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
package org.hyperledger.besu.ethereum.eth.manager.task; |
||||
|
||||
import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil; |
||||
import org.hyperledger.besu.ethereum.eth.manager.EthMessages; |
||||
import org.hyperledger.besu.ethereum.eth.manager.EthPeers; |
||||
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; |
||||
import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer; |
||||
import org.hyperledger.besu.ethereum.eth.manager.snap.SnapProtocolManager; |
||||
import org.hyperledger.besu.ethereum.worldstate.DataStorageFormat; |
||||
import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; |
||||
|
||||
import java.util.Collections; |
||||
|
||||
public class SnapProtocolManagerTestUtil { |
||||
|
||||
public static SnapProtocolManager create(final EthPeers ethPeers) { |
||||
return create( |
||||
BlockchainSetupUtil.forTesting(DataStorageFormat.FOREST).getWorldArchive(), ethPeers); |
||||
} |
||||
|
||||
public static SnapProtocolManager create( |
||||
final WorldStateArchive worldStateArchive, final EthPeers ethPeers) { |
||||
|
||||
EthMessages messages = new EthMessages(); |
||||
|
||||
return new SnapProtocolManager(Collections.emptyList(), ethPeers, messages, worldStateArchive); |
||||
} |
||||
|
||||
public static SnapProtocolManager create( |
||||
final WorldStateArchive worldStateArchive, |
||||
final EthPeers ethPeers, |
||||
final EthMessages snapMessages) { |
||||
return new SnapProtocolManager( |
||||
Collections.emptyList(), ethPeers, snapMessages, worldStateArchive); |
||||
} |
||||
|
||||
public static RespondingEthPeer createPeer( |
||||
final EthProtocolManager ethProtocolManager, |
||||
final SnapProtocolManager snapProtocolManager, |
||||
final long estimatedHeight) { |
||||
return RespondingEthPeer.builder() |
||||
.ethProtocolManager(ethProtocolManager) |
||||
.snapProtocolManager(snapProtocolManager) |
||||
.estimatedHeight(estimatedHeight) |
||||
.build(); |
||||
} |
||||
} |
@ -0,0 +1,261 @@ |
||||
/* |
||||
* Copyright contributors to Hyperledger Besu |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
package org.hyperledger.besu.ethereum.eth.sync.worldstate; |
||||
|
||||
import static org.mockito.Mockito.mock; |
||||
import static org.mockito.Mockito.when; |
||||
|
||||
import org.hyperledger.besu.datatypes.Hash; |
||||
import org.hyperledger.besu.ethereum.chain.Blockchain; |
||||
import org.hyperledger.besu.ethereum.core.BlockHeader; |
||||
import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; |
||||
import org.hyperledger.besu.ethereum.eth.manager.EthPeers; |
||||
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; |
||||
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; |
||||
import org.hyperledger.besu.ethereum.eth.manager.PeerRequest; |
||||
import org.hyperledger.besu.ethereum.eth.manager.RequestManager; |
||||
import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer; |
||||
import org.hyperledger.besu.ethereum.eth.manager.snap.SnapProtocolManager; |
||||
import org.hyperledger.besu.ethereum.eth.manager.task.SnapProtocolManagerTestUtil; |
||||
import org.hyperledger.besu.ethereum.eth.messages.EthPV63; |
||||
import org.hyperledger.besu.ethereum.eth.messages.NodeDataMessage; |
||||
import org.hyperledger.besu.ethereum.eth.messages.snap.SnapV1; |
||||
import org.hyperledger.besu.ethereum.eth.messages.snap.TrieNodesMessage; |
||||
import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; |
||||
|
||||
import java.math.BigInteger; |
||||
import java.util.List; |
||||
import java.util.Optional; |
||||
|
||||
import org.apache.tuweni.bytes.Bytes; |
||||
import org.apache.tuweni.bytes.Bytes32; |
||||
import org.assertj.core.api.Assertions; |
||||
import org.junit.Before; |
||||
import org.junit.Test; |
||||
import org.junit.runner.RunWith; |
||||
import org.mockito.Mock; |
||||
import org.mockito.junit.MockitoJUnitRunner; |
||||
|
||||
@SuppressWarnings({"FieldCanBeLocal", "unused"}) |
||||
@RunWith(MockitoJUnitRunner.class) |
||||
public class WorldStatePeerTrieNodeFinderTest { |
||||
|
||||
WorldStatePeerTrieNodeFinder worldStatePeerTrieNodeFinder; |
||||
|
||||
private final BlockHeaderTestFixture blockHeaderBuilder = new BlockHeaderTestFixture(); |
||||
|
||||
@Mock private Blockchain blockchain; |
||||
private EthProtocolManager ethProtocolManager; |
||||
private SnapProtocolManager snapProtocolManager; |
||||
private EthPeers ethPeers; |
||||
private final PeerRequest peerRequest = mock(PeerRequest.class); |
||||
private final RequestManager.ResponseStream responseStream = |
||||
mock(RequestManager.ResponseStream.class); |
||||
|
||||
@Before |
||||
public void setup() throws Exception { |
||||
ethProtocolManager = EthProtocolManagerTestUtil.create(); |
||||
ethPeers = ethProtocolManager.ethContext().getEthPeers(); |
||||
snapProtocolManager = SnapProtocolManagerTestUtil.create(ethPeers); |
||||
worldStatePeerTrieNodeFinder = |
||||
new WorldStatePeerTrieNodeFinder( |
||||
ethProtocolManager.ethContext(), blockchain, new NoOpMetricsSystem()); |
||||
} |
||||
|
||||
private RespondingEthPeer.Responder respondToGetNodeDataRequest( |
||||
final RespondingEthPeer peer, final Bytes32 nodeValue) { |
||||
return RespondingEthPeer.targetedResponder( |
||||
(cap, msg) -> { |
||||
if (msg.getCode() != EthPV63.GET_NODE_DATA) { |
||||
return false; |
||||
} |
||||
return true; |
||||
}, |
||||
(cap, msg) -> NodeDataMessage.create(List.of(nodeValue))); |
||||
} |
||||
|
||||
private RespondingEthPeer.Responder respondToGetTrieNodeRequest( |
||||
final RespondingEthPeer peer, final Bytes32 nodeValue) { |
||||
return RespondingEthPeer.targetedResponder( |
||||
(cap, msg) -> { |
||||
if (msg.getCode() != SnapV1.GET_TRIE_NODES) { |
||||
return false; |
||||
} |
||||
return true; |
||||
}, |
||||
(cap, msg) -> TrieNodesMessage.create(Optional.of(BigInteger.ZERO), List.of(nodeValue))); |
||||
} |
||||
|
||||
@Test |
||||
public void getAccountStateTrieNodeShouldReturnValueFromGetNodeDataRequest() { |
||||
|
||||
BlockHeader blockHeader = blockHeaderBuilder.number(1000).buildHeader(); |
||||
when(blockchain.getChainHeadHeader()).thenReturn(blockHeader); |
||||
|
||||
final Bytes32 nodeValue = Bytes32.random(); |
||||
final Bytes32 nodeHash = Hash.hash(nodeValue); |
||||
|
||||
final RespondingEthPeer targetPeer = |
||||
EthProtocolManagerTestUtil.createPeer(ethProtocolManager, blockHeader.getNumber()); |
||||
|
||||
var response = |
||||
new Object() { |
||||
Optional<Bytes> accountStateTrieNode = Optional.empty(); |
||||
}; |
||||
|
||||
new Thread( |
||||
() -> |
||||
targetPeer.respondWhileOtherThreadsWork( |
||||
respondToGetNodeDataRequest(targetPeer, nodeValue), |
||||
() -> response.accountStateTrieNode.isEmpty())) |
||||
.start(); |
||||
|
||||
response.accountStateTrieNode = |
||||
worldStatePeerTrieNodeFinder.getAccountStateTrieNode(Bytes.EMPTY, nodeHash); |
||||
|
||||
Assertions.assertThat(response.accountStateTrieNode).contains(nodeValue); |
||||
} |
||||
|
||||
@Test |
||||
public void getAccountStateTrieNodeShouldReturnValueFromGetTrieNodeRequest() { |
||||
|
||||
final BlockHeader blockHeader = blockHeaderBuilder.number(1000).buildHeader(); |
||||
when(blockchain.getChainHeadHeader()).thenReturn(blockHeader); |
||||
|
||||
final Bytes32 nodeValue = Bytes32.random(); |
||||
final Bytes32 nodeHash = Hash.hash(nodeValue); |
||||
|
||||
final RespondingEthPeer targetPeer = |
||||
SnapProtocolManagerTestUtil.createPeer( |
||||
ethProtocolManager, snapProtocolManager, blockHeader.getNumber()); |
||||
|
||||
var response = |
||||
new Object() { |
||||
Optional<Bytes> accountStateTrieNode = Optional.empty(); |
||||
}; |
||||
|
||||
new Thread( |
||||
() -> |
||||
targetPeer.respondWhileOtherThreadsWork( |
||||
respondToGetTrieNodeRequest(targetPeer, nodeValue), |
||||
() -> response.accountStateTrieNode.isEmpty())) |
||||
.start(); |
||||
|
||||
response.accountStateTrieNode = |
||||
worldStatePeerTrieNodeFinder.getAccountStateTrieNode(Bytes.EMPTY, nodeHash); |
||||
Assertions.assertThat(response.accountStateTrieNode).contains(nodeValue); |
||||
} |
||||
|
||||
@Test |
||||
public void getAccountStateTrieNodeShouldReturnEmptyWhenFoundNothing() { |
||||
|
||||
final BlockHeader blockHeader = blockHeaderBuilder.number(1000).buildHeader(); |
||||
when(blockchain.getChainHeadHeader()).thenReturn(blockHeader); |
||||
|
||||
final Bytes32 nodeValue = Bytes32.random(); |
||||
final Bytes32 nodeHash = Hash.hash(nodeValue); |
||||
|
||||
var response = |
||||
new Object() { |
||||
Optional<Bytes> accountStateTrieNode = Optional.empty(); |
||||
}; |
||||
|
||||
response.accountStateTrieNode = |
||||
worldStatePeerTrieNodeFinder.getAccountStateTrieNode(Bytes.EMPTY, nodeHash); |
||||
Assertions.assertThat(response.accountStateTrieNode).isEmpty(); |
||||
} |
||||
|
||||
@Test |
||||
public void getAccountStorageTrieNodeShouldReturnValueFromGetNodeDataRequest() { |
||||
|
||||
BlockHeader blockHeader = blockHeaderBuilder.number(1000).buildHeader(); |
||||
when(blockchain.getChainHeadHeader()).thenReturn(blockHeader); |
||||
|
||||
final Hash accountHash = Hash.wrap(Bytes32.random()); |
||||
final Bytes32 nodeValue = Bytes32.random(); |
||||
final Bytes32 nodeHash = Hash.hash(nodeValue); |
||||
|
||||
final RespondingEthPeer targetPeer = |
||||
EthProtocolManagerTestUtil.createPeer(ethProtocolManager, blockHeader.getNumber()); |
||||
|
||||
var response = |
||||
new Object() { |
||||
Optional<Bytes> accountStateTrieNode = Optional.empty(); |
||||
}; |
||||
|
||||
new Thread( |
||||
() -> |
||||
targetPeer.respondWhileOtherThreadsWork( |
||||
respondToGetNodeDataRequest(targetPeer, nodeValue), |
||||
() -> response.accountStateTrieNode.isEmpty())) |
||||
.start(); |
||||
|
||||
response.accountStateTrieNode = |
||||
worldStatePeerTrieNodeFinder.getAccountStorageTrieNode(accountHash, Bytes.EMPTY, nodeHash); |
||||
|
||||
Assertions.assertThat(response.accountStateTrieNode).contains(nodeValue); |
||||
} |
||||
|
||||
@Test |
||||
public void getAccountStorageTrieNodeShouldReturnValueFromGetTrieNodeRequest() { |
||||
|
||||
final BlockHeader blockHeader = blockHeaderBuilder.number(1000).buildHeader(); |
||||
when(blockchain.getChainHeadHeader()).thenReturn(blockHeader); |
||||
|
||||
final Hash accountHash = Hash.wrap(Bytes32.random()); |
||||
final Bytes32 nodeValue = Bytes32.random(); |
||||
final Bytes32 nodeHash = Hash.hash(nodeValue); |
||||
|
||||
final RespondingEthPeer targetPeer = |
||||
SnapProtocolManagerTestUtil.createPeer( |
||||
ethProtocolManager, snapProtocolManager, blockHeader.getNumber()); |
||||
|
||||
var response = |
||||
new Object() { |
||||
Optional<Bytes> accountStateTrieNode = Optional.empty(); |
||||
}; |
||||
|
||||
new Thread( |
||||
() -> |
||||
targetPeer.respondWhileOtherThreadsWork( |
||||
respondToGetTrieNodeRequest(targetPeer, nodeValue), |
||||
() -> response.accountStateTrieNode.isEmpty())) |
||||
.start(); |
||||
|
||||
response.accountStateTrieNode = |
||||
worldStatePeerTrieNodeFinder.getAccountStorageTrieNode(accountHash, Bytes.EMPTY, nodeHash); |
||||
Assertions.assertThat(response.accountStateTrieNode).contains(nodeValue); |
||||
} |
||||
|
||||
@Test |
||||
public void getAccountStorageTrieNodeShouldReturnEmptyWhenFoundNothing() { |
||||
|
||||
final BlockHeader blockHeader = blockHeaderBuilder.number(1000).buildHeader(); |
||||
when(blockchain.getChainHeadHeader()).thenReturn(blockHeader); |
||||
|
||||
final Hash accountHash = Hash.wrap(Bytes32.random()); |
||||
final Bytes32 nodeValue = Bytes32.random(); |
||||
final Bytes32 nodeHash = Hash.hash(nodeValue); |
||||
|
||||
var response = |
||||
new Object() { |
||||
Optional<Bytes> accountStateTrieNode = Optional.empty(); |
||||
}; |
||||
|
||||
response.accountStateTrieNode = |
||||
worldStatePeerTrieNodeFinder.getAccountStorageTrieNode(accountHash, Bytes.EMPTY, nodeHash); |
||||
Assertions.assertThat(response.accountStateTrieNode).isEmpty(); |
||||
} |
||||
} |
Loading…
Reference in new issue