use of com.radixdlt.ledger.AccumulatorState in project radixdlt by radixdlt.
the class LedgerProofTest method testGetters.
@Test
public void testGetters() {
LedgerHeader l0 = mock(LedgerHeader.class);
HashCode accumulatorHash = mock(HashCode.class);
View view = mock(View.class);
when(l0.getEpoch()).thenReturn(3L);
AccumulatorState accumulatorState = mock(AccumulatorState.class);
when(accumulatorState.getAccumulatorHash()).thenReturn(accumulatorHash);
when(accumulatorState.getStateVersion()).thenReturn(12345L);
when(l0.getAccumulatorState()).thenReturn(accumulatorState);
when(l0.getView()).thenReturn(view);
when(l0.timestamp()).thenReturn(2468L);
when(l0.isEndOfEpoch()).thenReturn(true);
var ledgerHeaderAndProof = new LedgerProof(HashUtils.random256(), l0, mock(TimestampedECDSASignatures.class));
assertThat(ledgerHeaderAndProof.getEpoch()).isEqualTo(3L);
assertThat(ledgerHeaderAndProof.getStateVersion()).isEqualTo(12345L);
assertThat(ledgerHeaderAndProof.getView()).isEqualTo(view);
assertThat(ledgerHeaderAndProof.timestamp()).isEqualTo(2468L);
assertThat(ledgerHeaderAndProof.isEndOfEpoch()).isTrue();
}
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 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));
}
};
}
Aggregations