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();
}
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());
}
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();
}
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();
}
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);
}
Aggregations