use of com.radixdlt.ledger.AccumulatorState in project radixdlt by radixdlt.
the class BerkeleyLedgerEntryStoreTest method storeMetadataWithForks.
private void storeMetadataWithForks(long epoch, ImmutableSet<ForkVotingResult> forkVotingResults) throws RadixEngineException {
final var fakeTx = mock(REProcessedTxn.class);
final var txn = mock(Txn.class);
when(txn.getId()).thenReturn(AID.from(HashUtils.random256().asBytes()));
when(fakeTx.getTxn()).thenReturn(txn);
when(fakeTx.getGroupedStateUpdates()).thenReturn(List.of());
when(txn.getPayload()).thenReturn(HashUtils.random256().asBytes());
final var proof1 = LedgerAndBFTProof.create(new LedgerProof(HashUtils.random256(), LedgerHeader.create(epoch, View.of(0L), new AccumulatorState(epoch, /* using same state version as epoch */
HashCode.fromInt(1)), 0L), new TimestampedECDSASignatures(Map.of()))).withForksVotingResults(forkVotingResults);
sut.transaction(tx -> {
tx.storeTxn(fakeTx);
tx.storeMetadata(proof1);
return null;
});
}
use of com.radixdlt.ledger.AccumulatorState in project radixdlt by radixdlt.
the class MockedRecoveryModule method configuration.
@Provides
private BFTConfiguration configuration(@LastEpochProof LedgerProof proof, BFTValidatorSet validatorSet, Hasher hasher) {
var accumulatorState = new AccumulatorState(0, genesisHash);
UnverifiedVertex genesis = UnverifiedVertex.createGenesis(LedgerHeader.genesis(accumulatorState, validatorSet, 0));
VerifiedVertex verifiedGenesis = new VerifiedVertex(genesis, genesisHash);
LedgerHeader nextLedgerHeader = LedgerHeader.create(proof.getEpoch() + 1, View.genesis(), proof.getAccumulatorState(), proof.timestamp());
var genesisQC = QuorumCertificate.ofGenesis(verifiedGenesis, nextLedgerHeader);
var proposerElection = new WeightedRotatingLeaders(validatorSet);
return new BFTConfiguration(proposerElection, validatorSet, VerifiedVertexStoreState.create(HighQC.from(genesisQC), verifiedGenesis, Optional.empty(), hasher));
}
use of com.radixdlt.ledger.AccumulatorState in project radixdlt by radixdlt.
the class ConsensusModuleTest method createNextVertex.
private Pair<QuorumCertificate, VerifiedVertex> createNextVertex(QuorumCertificate parent, ECKeyPair proposerKeyPair, Txn txn) {
final var proposerBftNode = BFTNode.create(proposerKeyPair.getPublicKey());
var unverifiedVertex = UnverifiedVertex.create(parent, View.of(1), List.of(txn), proposerBftNode);
var hash = hasher.hash(unverifiedVertex);
var verifiedVertex = new VerifiedVertex(unverifiedVertex, hash);
var next = new BFTHeader(View.of(1), verifiedVertex.getId(), LedgerHeader.create(1, View.of(1), new AccumulatorState(1, HashUtils.zero256()), 1));
final var voteData = new VoteData(next, parent.getProposed(), parent.getParent());
final var timestamp = 1;
final var voteDataHash = Vote.getHashOfData(hasher, voteData, timestamp);
final var qcSignature = proposerKeyPair.sign(voteDataHash);
var unsyncedQC = new QuorumCertificate(voteData, new TimestampedECDSASignatures(Map.of(proposerBftNode, TimestampedECDSASignature.from(timestamp, qcSignature))));
return Pair.of(unsyncedQC, verifiedVertex);
}
use of com.radixdlt.ledger.AccumulatorState in project radixdlt by radixdlt.
the class EpochManagerTest method getExternalModule.
private Module getExternalModule() {
BFTNode self = BFTNode.create(ecKeyPair.getPublicKey());
return new AbstractModule() {
@Override
protected void configure() {
bind(HashSigner.class).toInstance(ecKeyPair::sign);
bind(BFTNode.class).annotatedWith(Self.class).toInstance(self);
bind(new TypeLiteral<EventDispatcher<LocalTimeoutOccurrence>>() {
}).toInstance(rmock(EventDispatcher.class));
bind(new TypeLiteral<EventDispatcher<BFTInsertUpdate>>() {
}).toInstance(rmock(EventDispatcher.class));
bind(new TypeLiteral<EventDispatcher<BFTRebuildUpdate>>() {
}).toInstance(rmock(EventDispatcher.class));
bind(new TypeLiteral<EventDispatcher<BFTHighQCUpdate>>() {
}).toInstance(rmock(EventDispatcher.class));
bind(new TypeLiteral<EventDispatcher<BFTCommittedUpdate>>() {
}).toInstance(rmock(EventDispatcher.class));
bind(new TypeLiteral<EventDispatcher<EpochLocalTimeoutOccurrence>>() {
}).toInstance(rmock(EventDispatcher.class));
bind(new TypeLiteral<EventDispatcher<EpochView>>() {
}).toInstance(rmock(EventDispatcher.class));
bind(new TypeLiteral<EventDispatcher<LocalSyncRequest>>() {
}).toInstance(syncLedgerRequestSender);
bind(new TypeLiteral<EventDispatcher<ViewQuorumReached>>() {
}).toInstance(rmock(EventDispatcher.class));
bind(new TypeLiteral<EventDispatcher<EpochViewUpdate>>() {
}).toInstance(rmock(EventDispatcher.class));
bind(new TypeLiteral<EventDispatcher<ViewUpdate>>() {
}).toInstance(rmock(EventDispatcher.class));
bind(new TypeLiteral<EventDispatcher<NoVote>>() {
}).toInstance(rmock(EventDispatcher.class));
bind(new TypeLiteral<EventDispatcher<LedgerUpdate>>() {
}).toInstance(rmock(EventDispatcher.class));
bind(new TypeLiteral<ScheduledEventDispatcher<GetVerticesRequest>>() {
}).toInstance(timeoutScheduler);
bind(new TypeLiteral<ScheduledEventDispatcher<ScheduledLocalTimeout>>() {
}).toInstance(rmock(ScheduledEventDispatcher.class));
bind(new TypeLiteral<ScheduledEventDispatcher<Epoched<ScheduledLocalTimeout>>>() {
}).toInstance(rmock(ScheduledEventDispatcher.class));
bind(new TypeLiteral<ScheduledEventDispatcher<VertexRequestTimeout>>() {
}).toInstance(rmock(ScheduledEventDispatcher.class));
bind(new TypeLiteral<RemoteEventDispatcher<Proposal>>() {
}).toInstance(proposalDispatcher);
bind(new TypeLiteral<RemoteEventDispatcher<Vote>>() {
}).toInstance(voteDispatcher);
bind(new TypeLiteral<RemoteEventDispatcher<GetVerticesRequest>>() {
}).toInstance(rmock(RemoteEventDispatcher.class));
bind(new TypeLiteral<RemoteEventDispatcher<GetVerticesResponse>>() {
}).toInstance(rmock(RemoteEventDispatcher.class));
bind(new TypeLiteral<RemoteEventDispatcher<GetVerticesErrorResponse>>() {
}).toInstance(rmock(RemoteEventDispatcher.class));
bind(new TypeLiteral<RemoteEventDispatcher<LedgerStatusUpdate>>() {
}).toInstance(rmock(RemoteEventDispatcher.class));
bind(PersistentSafetyStateStore.class).toInstance(mock(PersistentSafetyStateStore.class));
bind(NextTxnsGenerator.class).toInstance(nextTxnsGenerator);
bind(SystemCounters.class).toInstance(new SystemCountersImpl());
bind(Mempool.class).toInstance(mempool);
bind(StateComputer.class).toInstance(stateComputer);
bind(PersistentVertexStore.class).toInstance(mock(PersistentVertexStore.class));
bind(RateLimiter.class).annotatedWith(GetVerticesRequestRateLimit.class).toInstance(RateLimiter.create(Double.MAX_VALUE));
bindConstant().annotatedWith(BFTSyncPatienceMillis.class).to(50);
bindConstant().annotatedWith(PacemakerTimeout.class).to(10L);
bindConstant().annotatedWith(PacemakerRate.class).to(2.0);
bindConstant().annotatedWith(PacemakerMaxExponent.class).to(0);
bind(TimeSupplier.class).toInstance(System::currentTimeMillis);
bind(new TypeLiteral<Consumer<EpochViewUpdate>>() {
}).toInstance(rmock(Consumer.class));
}
@Provides
private ViewUpdate view(BFTConfiguration bftConfiguration) {
HighQC highQC = bftConfiguration.getVertexStoreState().getHighQC();
View view = highQC.highestQC().getView().next();
return ViewUpdate.create(view, highQC, self, self);
}
@Provides
BFTValidatorSet validatorSet() {
return BFTValidatorSet.from(Stream.of(BFTValidator.from(self, UInt256.ONE)));
}
@Provides
@LastProof
LedgerProof verifiedLedgerHeaderAndProof(BFTValidatorSet validatorSet) {
var accumulatorState = new AccumulatorState(0, HashUtils.zero256());
return LedgerProof.genesis(accumulatorState, validatorSet, 0);
}
@Provides
@LastEpochProof
LedgerProof lastEpochProof(BFTValidatorSet validatorSet) {
var accumulatorState = new AccumulatorState(0, HashUtils.zero256());
return LedgerProof.genesis(accumulatorState, validatorSet, 0);
}
@Provides
BFTConfiguration bftConfiguration(@Self BFTNode self, Hasher hasher, BFTValidatorSet validatorSet) {
var accumulatorState = new AccumulatorState(0, HashUtils.zero256());
var unverifiedVertex = UnverifiedVertex.createGenesis(LedgerHeader.genesis(accumulatorState, validatorSet, 0));
var verifiedVertex = new VerifiedVertex(unverifiedVertex, hasher.hash(unverifiedVertex));
var qc = QuorumCertificate.ofGenesis(verifiedVertex, LedgerHeader.genesis(accumulatorState, validatorSet, 0));
var proposerElection = new WeightedRotatingLeaders(validatorSet);
return new BFTConfiguration(proposerElection, validatorSet, VerifiedVertexStoreState.create(HighQC.from(qc), verifiedVertex, Optional.empty(), hasher));
}
};
}
use of com.radixdlt.ledger.AccumulatorState in project radixdlt by radixdlt.
the class MempoolTest method replay_command_to_mempool.
@Test
public void replay_command_to_mempool() throws Exception {
// Arrange
getInjector().injectMembers(this);
ECKeyPair keyPair = ECKeyPair.generateNew();
var txn = createTxn(keyPair);
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(txn), proof);
stateComputer.commit(commandsAndProof, null);
// Act
MempoolAdd mempoolAdd = MempoolAdd.create(txn);
processor.handleMessage(getFirstPeer(), mempoolAdd, null);
// Assert
assertThat(systemCounters.get(CounterType.MEMPOOL_CURRENT_SIZE)).isZero();
}
Aggregations