Search in sources :

Example 21 with AccumulatorState

use of com.radixdlt.ledger.AccumulatorState in project radixdlt by radixdlt.

the class LedgerProofTest method testComparsionEqual.

@Test
public void testComparsionEqual() {
    LedgerHeader l0 = mock(LedgerHeader.class);
    when(l0.getEpoch()).thenReturn(2L);
    AccumulatorState accumulatorState = mock(AccumulatorState.class);
    when(accumulatorState.getStateVersion()).thenReturn(3L);
    when(l0.getAccumulatorState()).thenReturn(accumulatorState);
    when(l0.isEndOfEpoch()).thenReturn(true);
    LedgerProof s0 = new LedgerProof(HashUtils.random256(), l0, mock(TimestampedECDSASignatures.class));
    LedgerHeader l1 = mock(LedgerHeader.class);
    when(l1.getEpoch()).thenReturn(2L);
    AccumulatorState accumulatorState1 = mock(AccumulatorState.class);
    when(accumulatorState1.getStateVersion()).thenReturn(3L);
    when(l1.getAccumulatorState()).thenReturn(accumulatorState1);
    when(l1.isEndOfEpoch()).thenReturn(true);
    LedgerProof s1 = new LedgerProof(HashUtils.random256(), l1, mock(TimestampedECDSASignatures.class));
    assertThat(headerComparator.compare(s0, s1)).isZero();
    assertThat(headerComparator.compare(s1, s0)).isZero();
}
Also used : AccumulatorState(com.radixdlt.ledger.AccumulatorState) Test(org.junit.Test)

Example 22 with AccumulatorState

use of com.radixdlt.ledger.AccumulatorState in project radixdlt by radixdlt.

the class EpochManagerTest method should_not_send_consensus_messages_if_not_part_of_new_epoch.

@Test
public void should_not_send_consensus_messages_if_not_part_of_new_epoch() {
    // Arrange
    epochManager.start();
    BFTValidatorSet nextValidatorSet = BFTValidatorSet.from(Stream.of(BFTValidator.from(BFTNode.random(), UInt256.ONE)));
    var accumulatorState = new AccumulatorState(0, HashUtils.zero256());
    LedgerHeader header = LedgerHeader.genesis(accumulatorState, nextValidatorSet, 0);
    UnverifiedVertex genesisVertex = UnverifiedVertex.createGenesis(header);
    VerifiedVertex verifiedGenesisVertex = new VerifiedVertex(genesisVertex, hasher.hash(genesisVertex));
    LedgerHeader nextLedgerHeader = LedgerHeader.create(header.getEpoch() + 1, View.genesis(), header.getAccumulatorState(), header.timestamp());
    var genesisQC = QuorumCertificate.ofGenesis(verifiedGenesisVertex, nextLedgerHeader);
    var proposerElection = new WeightedRotatingLeaders(nextValidatorSet);
    var bftConfiguration = new BFTConfiguration(proposerElection, nextValidatorSet, VerifiedVertexStoreState.create(HighQC.from(genesisQC), verifiedGenesisVertex, Optional.empty(), hasher));
    LedgerProof proof = mock(LedgerProof.class);
    when(proof.getEpoch()).thenReturn(header.getEpoch() + 1);
    var epochChange = new EpochChange(proof, bftConfiguration);
    var ledgerUpdate = new LedgerUpdate(mock(VerifiedTxnsAndProof.class), ImmutableClassToInstanceMap.of(EpochChange.class, epochChange));
    // Act
    epochManager.epochsLedgerUpdateEventProcessor().process(ledgerUpdate);
    // Assert
    verify(proposalDispatcher, never()).dispatch(any(Iterable.class), argThat(p -> p.getEpoch() == epochChange.getEpoch()));
    verify(voteDispatcher, never()).dispatch(any(BFTNode.class), any());
}
Also used : LedgerUpdate(com.radixdlt.ledger.LedgerUpdate) Module(com.google.inject.Module) BFTHighQCUpdate(com.radixdlt.hotstuff.bft.BFTHighQCUpdate) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) Inject(com.google.inject.Inject) PersistentSafetyStateStore(com.radixdlt.hotstuff.safety.PersistentSafetyStateStore) Hasher(com.radixdlt.crypto.Hasher) HighQC(com.radixdlt.hotstuff.HighQC) EpochLocalTimeoutOccurrence(com.radixdlt.hotstuff.liveness.EpochLocalTimeoutOccurrence) VerifiedVertexStoreState(com.radixdlt.hotstuff.bft.VerifiedVertexStoreState) MempoolAdd(com.radixdlt.mempool.MempoolAdd) RemoteEventDispatcher(com.radixdlt.environment.RemoteEventDispatcher) QuorumCertificate(com.radixdlt.hotstuff.QuorumCertificate) LedgerHeader(com.radixdlt.hotstuff.LedgerHeader) EpochsConsensusModule(com.radixdlt.modules.EpochsConsensusModule) VerifiedTxnsAndProof(com.radixdlt.ledger.VerifiedTxnsAndProof) Map(java.util.Map) PersistentVertexStore(com.radixdlt.hotstuff.bft.PersistentVertexStore) PacemakerTimeout(com.radixdlt.hotstuff.bft.PacemakerTimeout) GetVerticesErrorResponse(com.radixdlt.hotstuff.sync.GetVerticesErrorResponse) BFTRebuildUpdate(com.radixdlt.hotstuff.bft.BFTRebuildUpdate) HashUtils(com.radixdlt.crypto.HashUtils) BFTSyncPatienceMillis(com.radixdlt.hotstuff.sync.BFTSyncPatienceMillis) BFTInsertUpdate(com.radixdlt.hotstuff.bft.BFTInsertUpdate) SystemCounters(com.radixdlt.counters.SystemCounters) Vote(com.radixdlt.hotstuff.Vote) ConsensusModule(com.radixdlt.modules.ConsensusModule) NextTxnsGenerator(com.radixdlt.hotstuff.liveness.NextTxnsGenerator) StateComputerResult(com.radixdlt.ledger.StateComputerLedger.StateComputerResult) VerifiedVertex(com.radixdlt.hotstuff.bft.VerifiedVertex) ViewUpdate(com.radixdlt.hotstuff.bft.ViewUpdate) StateComputer(com.radixdlt.ledger.StateComputerLedger.StateComputer) GetVerticesRequestRateLimit(com.radixdlt.middleware2.network.GetVerticesRequestRateLimit) PacemakerRate(com.radixdlt.hotstuff.bft.PacemakerRate) SystemCountersImpl(com.radixdlt.counters.SystemCountersImpl) List(java.util.List) Stream(java.util.stream.Stream) PacemakerMaxExponent(com.radixdlt.hotstuff.bft.PacemakerMaxExponent) LedgerModule(com.radixdlt.modules.LedgerModule) Optional(java.util.Optional) ImmutableClassToInstanceMap(com.google.common.collect.ImmutableClassToInstanceMap) TypeLiteral(com.google.inject.TypeLiteral) Proposal(com.radixdlt.hotstuff.Proposal) ViewQuorumReached(com.radixdlt.hotstuff.bft.ViewQuorumReached) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BFTCommittedUpdate(com.radixdlt.hotstuff.bft.BFTCommittedUpdate) CryptoModule(com.radixdlt.modules.CryptoModule) BFTValidatorSet(com.radixdlt.hotstuff.bft.BFTValidatorSet) ScheduledEventDispatcher(com.radixdlt.environment.ScheduledEventDispatcher) LedgerProof(com.radixdlt.hotstuff.LedgerProof) WeightedRotatingLeaders(com.radixdlt.hotstuff.liveness.WeightedRotatingLeaders) GetVerticesResponse(com.radixdlt.hotstuff.sync.GetVerticesResponse) PreparedTxn(com.radixdlt.ledger.StateComputerLedger.PreparedTxn) RateLimiter(com.google.common.util.concurrent.RateLimiter) TypedMocks.rmock(com.radixdlt.utils.TypedMocks.rmock) HashSigner(com.radixdlt.hotstuff.HashSigner) LocalSyncRequest(com.radixdlt.sync.messages.local.LocalSyncRequest) LedgerStatusUpdate(com.radixdlt.sync.messages.remote.LedgerStatusUpdate) View(com.radixdlt.hotstuff.bft.View) LastEpochProof(com.radixdlt.store.LastEpochProof) BFTConfiguration(com.radixdlt.hotstuff.BFTConfiguration) AccumulatorState(com.radixdlt.ledger.AccumulatorState) UInt256(com.radixdlt.utils.UInt256) Nullable(javax.annotation.Nullable) Before(org.junit.Before) TimeSupplier(com.radixdlt.utils.TimeSupplier) EventDispatcher(com.radixdlt.environment.EventDispatcher) ScheduledLocalTimeout(com.radixdlt.hotstuff.liveness.ScheduledLocalTimeout) NoVote(com.radixdlt.hotstuff.bft.NoVote) Txn(com.radixdlt.atom.Txn) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) UnverifiedVertex(com.radixdlt.hotstuff.UnverifiedVertex) BFTNode(com.radixdlt.hotstuff.bft.BFTNode) VertexRequestTimeout(com.radixdlt.hotstuff.sync.VertexRequestTimeout) LedgerUpdate(com.radixdlt.ledger.LedgerUpdate) Consumer(java.util.function.Consumer) Mockito.never(org.mockito.Mockito.never) Provides(com.google.inject.Provides) ECKeyPair(com.radixdlt.crypto.ECKeyPair) GetVerticesRequest(com.radixdlt.hotstuff.sync.GetVerticesRequest) BFTValidator(com.radixdlt.hotstuff.bft.BFTValidator) LocalTimeoutOccurrence(com.radixdlt.hotstuff.liveness.LocalTimeoutOccurrence) Guice(com.google.inject.Guice) Self(com.radixdlt.hotstuff.bft.Self) Mempool(com.radixdlt.mempool.Mempool) LastProof(com.radixdlt.store.LastProof) AbstractModule(com.google.inject.AbstractModule) BFTNode(com.radixdlt.hotstuff.bft.BFTNode) AccumulatorState(com.radixdlt.ledger.AccumulatorState) BFTValidatorSet(com.radixdlt.hotstuff.bft.BFTValidatorSet) UnverifiedVertex(com.radixdlt.hotstuff.UnverifiedVertex) VerifiedVertex(com.radixdlt.hotstuff.bft.VerifiedVertex) LedgerHeader(com.radixdlt.hotstuff.LedgerHeader) BFTConfiguration(com.radixdlt.hotstuff.BFTConfiguration) VerifiedTxnsAndProof(com.radixdlt.ledger.VerifiedTxnsAndProof) LedgerProof(com.radixdlt.hotstuff.LedgerProof) WeightedRotatingLeaders(com.radixdlt.hotstuff.liveness.WeightedRotatingLeaders) Test(org.junit.Test)

Example 23 with AccumulatorState

use of com.radixdlt.ledger.AccumulatorState in project radixdlt by radixdlt.

the class MempoolTest method mempool_removes_multiple_conflicts_on_commit.

@Test
public void mempool_removes_multiple_conflicts_on_commit() throws Exception {
    // Arrange
    getInjector().injectMembers(this);
    ECKeyPair keyPair = ECKeyPair.generateNew();
    var txn = createTxn(keyPair, 2);
    MempoolAdd mempoolAdd = MempoolAdd.create(txn);
    processor.handleMessage(getFirstPeer(), mempoolAdd, null);
    var txn2 = createTxn(keyPair, 3);
    processor.handleMessage(getFirstPeer(), MempoolAdd.create(txn2), null);
    // Act
    var txn3 = createTxn(keyPair, 1);
    var proof = mock(LedgerProof.class);
    when(proof.getAccumulatorState()).thenReturn(new AccumulatorState(genesisTxns.getTxns().size() + 1, HashUtils.random256()));
    when(proof.getStateVersion()).thenReturn((long) genesisTxns.getTxns().size() + 1);
    when(proof.getView()).thenReturn(View.of(1));
    var commandsAndProof = VerifiedTxnsAndProof.create(List.of(txn3), proof);
    stateComputer.commit(commandsAndProof, null);
    // Assert
    assertThat(systemCounters.get(CounterType.MEMPOOL_CURRENT_SIZE)).isZero();
}
Also used : AccumulatorState(com.radixdlt.ledger.AccumulatorState) ECKeyPair(com.radixdlt.crypto.ECKeyPair) Test(org.junit.Test)

Example 24 with AccumulatorState

use of com.radixdlt.ledger.AccumulatorState in project radixdlt by radixdlt.

the class MempoolTest method mempool_removes_conflicts_on_commit.

@Test
public void mempool_removes_conflicts_on_commit() throws Exception {
    // Arrange
    getInjector().injectMembers(this);
    ECKeyPair keyPair = ECKeyPair.generateNew();
    var txn = createTxn(keyPair, 2);
    MempoolAdd mempoolAdd = MempoolAdd.create(txn);
    processor.handleMessage(getFirstPeer(), mempoolAdd, null);
    // Act
    var txn2 = createTxn(keyPair, 1);
    var proof = mock(LedgerProof.class);
    when(proof.getAccumulatorState()).thenReturn(new AccumulatorState(genesisTxns.getTxns().size() + 1, HashUtils.random256()));
    when(proof.getStateVersion()).thenReturn((long) genesisTxns.getTxns().size() + 1);
    when(proof.getView()).thenReturn(View.of(1));
    var commandsAndProof = VerifiedTxnsAndProof.create(List.of(txn2), proof);
    stateComputer.commit(commandsAndProof, null);
    // Assert
    assertThat(systemCounters.get(CounterType.MEMPOOL_CURRENT_SIZE)).isZero();
}
Also used : AccumulatorState(com.radixdlt.ledger.AccumulatorState) ECKeyPair(com.radixdlt.crypto.ECKeyPair) Test(org.junit.Test)

Example 25 with AccumulatorState

use of com.radixdlt.ledger.AccumulatorState in project radixdlt by radixdlt.

the class ConsensusModuleTest method setup.

@Before
public void setup() {
    var accumulatorState = new AccumulatorState(0, HashUtils.zero256());
    var genesis = UnverifiedVertex.createGenesis(LedgerHeader.genesis(accumulatorState, null, 0));
    var hashedGenesis = new VerifiedVertex(genesis, HashUtils.zero256());
    var qc = QuorumCertificate.ofGenesis(hashedGenesis, LedgerHeader.genesis(accumulatorState, null, 0));
    this.validatorKeyPair = ECKeyPair.generateNew();
    this.validatorBftNode = BFTNode.create(this.validatorKeyPair.getPublicKey());
    var validatorSet = BFTValidatorSet.from(Stream.of(BFTValidator.from(this.validatorBftNode, UInt256.ONE)));
    var vertexStoreState = VerifiedVertexStoreState.create(HighQC.from(qc), hashedGenesis, Optional.empty(), hasher);
    var proposerElection = new WeightedRotatingLeaders(validatorSet);
    this.bftConfiguration = new BFTConfiguration(proposerElection, validatorSet, vertexStoreState);
    this.ecKeyPair = ECKeyPair.generateNew();
    this.requestSender = rmock(RemoteEventDispatcher.class);
    this.responseSender = rmock(RemoteEventDispatcher.class);
    this.errorResponseSender = rmock(RemoteEventDispatcher.class);
    Guice.createInjector(new ConsensusModule(), new CryptoModule(), getExternalModule()).injectMembers(this);
}
Also used : VerifiedVertex(com.radixdlt.hotstuff.bft.VerifiedVertex) AccumulatorState(com.radixdlt.ledger.AccumulatorState) BFTConfiguration(com.radixdlt.hotstuff.BFTConfiguration) RemoteEventDispatcher(com.radixdlt.environment.RemoteEventDispatcher) WeightedRotatingLeaders(com.radixdlt.hotstuff.liveness.WeightedRotatingLeaders) Before(org.junit.Before)

Aggregations

AccumulatorState (com.radixdlt.ledger.AccumulatorState)33 Test (org.junit.Test)19 LedgerProof (com.radixdlt.hotstuff.LedgerProof)10 TimestampedECDSASignatures (com.radixdlt.hotstuff.TimestampedECDSASignatures)9 VerifiedVertex (com.radixdlt.hotstuff.bft.VerifiedVertex)7 ECKeyPair (com.radixdlt.crypto.ECKeyPair)6 RemoteEventDispatcher (com.radixdlt.environment.RemoteEventDispatcher)6 AbstractModule (com.google.inject.AbstractModule)5 TypeLiteral (com.google.inject.TypeLiteral)5 SystemCounters (com.radixdlt.counters.SystemCounters)5 SystemCountersImpl (com.radixdlt.counters.SystemCountersImpl)5 Hasher (com.radixdlt.crypto.Hasher)5 EventDispatcher (com.radixdlt.environment.EventDispatcher)5 WeightedRotatingLeaders (com.radixdlt.hotstuff.liveness.WeightedRotatingLeaders)5 LedgerUpdate (com.radixdlt.ledger.LedgerUpdate)5 Before (org.junit.Before)5 Inject (com.google.inject.Inject)4 VerifiedVertex (com.radixdlt.consensus.bft.VerifiedVertex)4 ScheduledEventDispatcher (com.radixdlt.environment.ScheduledEventDispatcher)4 BFTConfiguration (com.radixdlt.hotstuff.BFTConfiguration)4