Search in sources :

Example 1 with PrivateBlockMetadata

use of org.hyperledger.besu.ethereum.privacy.storage.PrivateBlockMetadata in project besu by hyperledger.

the class PrivateStateRootResolverTest method resolveCorrectRootHashWhenMultipleCommitmentsExistForPrivacyGroup.

@Test
public void resolveCorrectRootHashWhenMultipleCommitmentsExistForPrivacyGroup() {
    final PrivateStateStorage.Updater updater = privateStateStorage.updater();
    updater.putPrivateBlockMetadata(BLOCKCHAIN.getBlockByNumber(16).get().getHash(), Bytes32.wrap(privacyGroupId), new PrivateBlockMetadata(Collections.singletonList(new PrivateTransactionMetadata(BLOCK_GENERATOR.transaction().getHash(), pmt1StateHash))));
    updater.putPrivateBlockMetadata(BLOCKCHAIN.getBlockByNumber(16).get().getHash(), Bytes32.wrap(failingPrivacyGroupId), new PrivateBlockMetadata(Collections.singletonList(new PrivateTransactionMetadata(BLOCK_GENERATOR.transaction().getHash(), pmt2StateHash))));
    updater.putPrivacyGroupHeadBlockMap(BLOCKCHAIN.getChainHeadHash(), new PrivacyGroupHeadBlockMap(Collections.singletonMap(Bytes32.wrap(privacyGroupId), BLOCKCHAIN.getBlockByNumber(16).get().getHash())));
    updater.commit();
    final PrivateStateRootResolver privateStateRootResolver = new PrivateStateRootResolver(privateStateStorage);
    assertThat(privateStateRootResolver.resolveLastStateRoot(privacyGroupId, BLOCKCHAIN.getChainHeadHash())).isEqualTo(pmt1StateHash);
}
Also used : PrivateTransactionMetadata(org.hyperledger.besu.ethereum.privacy.storage.PrivateTransactionMetadata) PrivateBlockMetadata(org.hyperledger.besu.ethereum.privacy.storage.PrivateBlockMetadata) PrivateStateStorage(org.hyperledger.besu.ethereum.privacy.storage.PrivateStateStorage) PrivacyGroupHeadBlockMap(org.hyperledger.besu.ethereum.privacy.storage.PrivacyGroupHeadBlockMap) Test(org.junit.Test)

Example 2 with PrivateBlockMetadata

use of org.hyperledger.besu.ethereum.privacy.storage.PrivateBlockMetadata in project besu by hyperledger.

the class PrivateMetadataUpdaterTest method addingMetadataSuccessfull.

@Test
public void addingMetadataSuccessfull() {
    when(blockHeader.getHash()).thenReturn(hashBlockOne);
    pmtHash = Hash.ZERO;
    final PrivateTransactionMetadata expected = new PrivateTransactionMetadata(pmtHash, stateRoot);
    updater.addPrivateTransactionMetadata(privacyGroupId, expected);
    updater.commit();
    final Optional<PrivateBlockMetadata> privateBlockMetadata = privateStateStorage.getPrivateBlockMetadata(hashBlockOne, privacyGroupId);
    assertThat(privateBlockMetadata.get().getLatestStateRoot().get()).isEqualTo(stateRoot);
}
Also used : PrivateTransactionMetadata(org.hyperledger.besu.ethereum.privacy.storage.PrivateTransactionMetadata) PrivateBlockMetadata(org.hyperledger.besu.ethereum.privacy.storage.PrivateBlockMetadata) Test(org.junit.Test)

Example 3 with PrivateBlockMetadata

use of org.hyperledger.besu.ethereum.privacy.storage.PrivateBlockMetadata in project besu by hyperledger.

the class PrivacyBlockProcessor method transactionsInGroupThatNeedToBeApplied.

private List<PrivateTransactionWithMetadata> transactionsInGroupThatNeedToBeApplied(final BlockHeader blockHeader, final List<PrivateTransactionWithMetadata> privateTransactionWithMetadataList, final Bytes32 privacyGroupId) {
    // if we are the member adding another member we do not have to rehydrate
    // if we have been removed from the group at some point we only need to rehydrate from where we
    // were removed
    // if we are a new member we need to rehydrate the complete state
    List<PrivateTransactionWithMetadata> actualList = privateTransactionWithMetadataList;
    final Optional<PrivacyGroupHeadBlockMap> maybePrivacyGroupHeadBlockMap = privateStateStorage.getPrivacyGroupHeadBlockMap(blockHeader.getParentHash());
    if (maybePrivacyGroupHeadBlockMap.isPresent()) {
        final PrivacyGroupHeadBlockMap privacyGroupHeadBlockMap = maybePrivacyGroupHeadBlockMap.get();
        final Hash lastBlockWithTx = privacyGroupHeadBlockMap.get(privacyGroupId);
        if (lastBlockWithTx != null) {
            // we are or have been a member of the privacy group
            final PrivateBlockMetadata nodeLatestBlockMetadata = privateStateStorage.getPrivateBlockMetadata(lastBlockWithTx, privacyGroupId).orElseThrow();
            final List<PrivateTransactionMetadata> nodeLatestPrivateTxMetadataList = nodeLatestBlockMetadata.getPrivateTransactionMetadataList();
            final Hash nodeLatestStateRoot = nodeLatestPrivateTxMetadataList.get(nodeLatestPrivateTxMetadataList.size() - 1).getStateRoot();
            final Hash latestStateRootFromRehydrationList = privateTransactionWithMetadataList.get(privateTransactionWithMetadataList.size() - 1).getPrivateTransactionMetadata().getStateRoot();
            if (nodeLatestStateRoot.equals(latestStateRootFromRehydrationList)) {
                // we are already on the latest state root, which means that we are the member adding a
                // new member
                actualList = Collections.emptyList();
            } else {
                // we are being added, but do not have to rehydrate all private transactions
                final Hash nodeLatestPrivateMarkerTransactionHash = nodeLatestPrivateTxMetadataList.get(nodeLatestPrivateTxMetadataList.size() - 1).getPrivateMarkerTransactionHash();
                for (int i = 0; i < privateTransactionWithMetadataList.size(); i++) {
                    if (!privateTransactionWithMetadataList.get(i).getPrivateTransactionMetadata().getPrivateMarkerTransactionHash().equals(nodeLatestPrivateMarkerTransactionHash)) {
                        continue;
                    }
                    if (privateTransactionWithMetadataList.size() - 1 == i) {
                        // nothing needs to be re-hydrated
                        actualList = Collections.emptyList();
                    } else {
                        actualList = privateTransactionWithMetadataList.subList(i + 1, privateTransactionWithMetadataList.size());
                    }
                    break;
                }
            }
        }
    }
    return actualList;
}
Also used : PrivateTransactionWithMetadata(org.hyperledger.besu.ethereum.privacy.PrivateTransactionWithMetadata) PrivateTransactionMetadata(org.hyperledger.besu.ethereum.privacy.storage.PrivateTransactionMetadata) PrivateBlockMetadata(org.hyperledger.besu.ethereum.privacy.storage.PrivateBlockMetadata) Hash(org.hyperledger.besu.datatypes.Hash) PrivacyGroupHeadBlockMap(org.hyperledger.besu.ethereum.privacy.storage.PrivacyGroupHeadBlockMap)

Example 4 with PrivateBlockMetadata

use of org.hyperledger.besu.ethereum.privacy.storage.PrivateBlockMetadata in project besu by hyperledger.

the class PrivateStateRootResolverTest method resolveLatestRootHashWhenMultipleCommitmentsForTheSamePrivacyGroupExist.

@Test
public void resolveLatestRootHashWhenMultipleCommitmentsForTheSamePrivacyGroupExist() {
    final PrivateStateStorage.Updater updater = privateStateStorage.updater();
    updater.putPrivateBlockMetadata(BLOCKCHAIN.getBlockByNumber(16).get().getHash(), Bytes32.wrap(privacyGroupId), new PrivateBlockMetadata(Arrays.asList(new PrivateTransactionMetadata(BLOCK_GENERATOR.transaction().getHash(), pmt1StateHash), new PrivateTransactionMetadata(BLOCK_GENERATOR.transaction().getHash(), pmt2StateHash))));
    updater.putPrivacyGroupHeadBlockMap(BLOCKCHAIN.getChainHeadHash(), new PrivacyGroupHeadBlockMap(Collections.singletonMap(Bytes32.wrap(privacyGroupId), BLOCKCHAIN.getBlockByNumber(16).get().getHash())));
    updater.commit();
    final PrivateStateRootResolver privateStateRootResolver = new PrivateStateRootResolver(privateStateStorage);
    assertThat(privateStateRootResolver.resolveLastStateRoot(privacyGroupId, BLOCKCHAIN.getChainHeadHash())).isEqualTo(pmt2StateHash);
}
Also used : PrivateTransactionMetadata(org.hyperledger.besu.ethereum.privacy.storage.PrivateTransactionMetadata) PrivateBlockMetadata(org.hyperledger.besu.ethereum.privacy.storage.PrivateBlockMetadata) PrivateStateStorage(org.hyperledger.besu.ethereum.privacy.storage.PrivateStateStorage) PrivacyGroupHeadBlockMap(org.hyperledger.besu.ethereum.privacy.storage.PrivacyGroupHeadBlockMap) Test(org.junit.Test)

Example 5 with PrivateBlockMetadata

use of org.hyperledger.besu.ethereum.privacy.storage.PrivateBlockMetadata in project besu by hyperledger.

the class PrivateStateRootResolverTest method resolveExpectedRootHashWhenCommitmentForPrivacyGroupExists.

@Test
public void resolveExpectedRootHashWhenCommitmentForPrivacyGroupExists() {
    final PrivateStateStorage.Updater updater = privateStateStorage.updater();
    updater.putPrivateBlockMetadata(BLOCKCHAIN.getBlockByNumber(16).get().getHash(), Bytes32.wrap(privacyGroupId), new PrivateBlockMetadata(Collections.singletonList(new PrivateTransactionMetadata(BLOCK_GENERATOR.transaction().getHash(), pmt1StateHash))));
    updater.putPrivacyGroupHeadBlockMap(BLOCKCHAIN.getChainHeadHash(), new PrivacyGroupHeadBlockMap(Collections.singletonMap(Bytes32.wrap(privacyGroupId), BLOCKCHAIN.getBlockByNumber(16).get().getHash())));
    updater.commit();
    final PrivateStateRootResolver privateStateRootResolver = new PrivateStateRootResolver(privateStateStorage);
    assertThat(privateStateRootResolver.resolveLastStateRoot(privacyGroupId, BLOCKCHAIN.getChainHeadHash())).isEqualTo(pmt1StateHash);
}
Also used : PrivateTransactionMetadata(org.hyperledger.besu.ethereum.privacy.storage.PrivateTransactionMetadata) PrivateBlockMetadata(org.hyperledger.besu.ethereum.privacy.storage.PrivateBlockMetadata) PrivateStateStorage(org.hyperledger.besu.ethereum.privacy.storage.PrivateStateStorage) PrivacyGroupHeadBlockMap(org.hyperledger.besu.ethereum.privacy.storage.PrivacyGroupHeadBlockMap) Test(org.junit.Test)

Aggregations

PrivateBlockMetadata (org.hyperledger.besu.ethereum.privacy.storage.PrivateBlockMetadata)11 PrivateTransactionMetadata (org.hyperledger.besu.ethereum.privacy.storage.PrivateTransactionMetadata)8 PrivacyGroupHeadBlockMap (org.hyperledger.besu.ethereum.privacy.storage.PrivacyGroupHeadBlockMap)6 Test (org.junit.Test)5 PrivateStateStorage (org.hyperledger.besu.ethereum.privacy.storage.PrivateStateStorage)4 Hash (org.hyperledger.besu.datatypes.Hash)3 Bytes32 (org.apache.tuweni.bytes.Bytes32)2 HashMap (java.util.HashMap)1 ReceiveResponse (org.hyperledger.besu.enclave.types.ReceiveResponse)1 SendResponse (org.hyperledger.besu.enclave.types.SendResponse)1 Blockchain (org.hyperledger.besu.ethereum.chain.Blockchain)1 Block (org.hyperledger.besu.ethereum.core.Block)1 BlockDataGenerator (org.hyperledger.besu.ethereum.core.BlockDataGenerator)1 BlockHeader (org.hyperledger.besu.ethereum.core.BlockHeader)1 MutableWorldState (org.hyperledger.besu.ethereum.core.MutableWorldState)1 PrivateTransactionDataFixture.generatePrivateBlockMetadata (org.hyperledger.besu.ethereum.core.PrivateTransactionDataFixture.generatePrivateBlockMetadata)1 Transaction (org.hyperledger.besu.ethereum.core.Transaction)1 PrivateTransactionWithMetadata (org.hyperledger.besu.ethereum.privacy.PrivateTransactionWithMetadata)1 LegacyPrivateStateStorage (org.hyperledger.besu.ethereum.privacy.storage.LegacyPrivateStateStorage)1 PrivateMetadataUpdater (org.hyperledger.besu.ethereum.privacy.storage.PrivateMetadataUpdater)1