use of com.radixdlt.ledger.DtoLedgerProof in project radixdlt by radixdlt.
the class BerkeleyLedgerEntryStore method getNextCommittedTxns.
@Override
public VerifiedTxnsAndProof getNextCommittedTxns(DtoLedgerProof start) {
long stateVersion = start.getLedgerHeader().getAccumulatorState().getStateVersion();
final var startTime = System.nanoTime();
com.sleepycat.je.Transaction txn = beginTransaction();
final LedgerProof nextHeader;
try (var proofCursor = proofDatabase.openCursor(txn, null)) {
final var headerSearchKey = toPKey(stateVersion + 1);
final var headerValue = entry();
var headerCursorStatus = proofCursor.getSearchKeyRange(headerSearchKey, headerValue, DEFAULT);
if (headerCursorStatus != SUCCESS) {
return null;
}
nextHeader = deserializeOrElseFail(headerValue.getData(), LedgerProof.class);
} finally {
txn.commit();
}
final var txns = ImmutableList.<Txn>builder();
final var atomSearchKey = toPKey(stateVersion + 1);
final var atomPosData = entry();
try (var txnCursor = txnDatabase.openCursor(null, null)) {
int atomCount = (int) (nextHeader.getStateVersion() - stateVersion);
int count = 0;
var atomCursorStatus = txnCursor.getSearchKeyRange(atomSearchKey, atomPosData, DEFAULT);
do {
if (atomCursorStatus != SUCCESS) {
throw new BerkeleyStoreException("Atom database search failure");
}
var offset = fromByteArray(atomPosData.getData());
var txnBytes = txnLog.read(offset);
txns.add(Txn.create(txnBytes));
atomCursorStatus = txnCursor.getNext(atomSearchKey, atomPosData, DEFAULT);
count++;
} while (count < atomCount);
return VerifiedTxnsAndProof.create(txns.build(), nextHeader);
} catch (IOException e) {
throw new BerkeleyStoreException("Unable to read from atom store.", e);
} finally {
addTime(startTime, CounterType.ELAPSED_BDB_LEDGER_ENTRIES, CounterType.COUNT_BDB_LEDGER_ENTRIES);
}
}
use of com.radixdlt.ledger.DtoLedgerProof in project radixdlt by radixdlt.
the class RemoteSyncResponseValidatorSetVerifierTest method setup.
@Before
public void setup() {
this.validatorSet = mock(BFTValidatorSet.class);
this.validatorSetVerifier = new RemoteSyncResponseValidatorSetVerifier(validatorSet);
commandsAndProof = mock(DtoTxnsAndProof.class);
DtoLedgerProof headerAndProof = mock(DtoLedgerProof.class);
TimestampedECDSASignatures signatures = mock(TimestampedECDSASignatures.class);
when(signatures.getSignatures()).thenReturn(ImmutableMap.of());
when(headerAndProof.getSignatures()).thenReturn(signatures);
when(commandsAndProof.getTail()).thenReturn(headerAndProof);
}
use of com.radixdlt.ledger.DtoLedgerProof in project radixdlt by radixdlt.
the class MessageCentralLedgerSyncTest method when_receive_sync_request__then_should_receive_it.
@Test
public void when_receive_sync_request__then_should_receive_it() {
TestSubscriber<RemoteEvent<SyncRequest>> testObserver = this.messageCentralLedgerSync.syncRequests().test();
final var peer = createPeer();
SyncRequestMessage syncRequestMessage = mock(SyncRequestMessage.class);
DtoLedgerProof header = mock(DtoLedgerProof.class);
when(syncRequestMessage.getCurrentHeader()).thenReturn(header);
messageCentral.send(peer, syncRequestMessage);
testObserver.awaitCount(1);
testObserver.assertValue(syncRequest -> syncRequest.getEvent().getHeader().equals(header) && syncRequest.getOrigin().getKey().equals(peer.getPublicKey()));
}
use of com.radixdlt.ledger.DtoLedgerProof in project radixdlt by radixdlt.
the class RemoteSyncServiceTest method when_remote_sync_request_and_unable__then_dont_do_anything.
@Test
public void when_remote_sync_request_and_unable__then_dont_do_anything() {
SyncRequest request = mock(SyncRequest.class);
DtoLedgerProof header = mock(DtoLedgerProof.class);
when(header.getOpaque()).thenReturn(HashUtils.zero256());
when(header.getLedgerHeader()).thenReturn(mock(LedgerHeader.class));
when(header.getSignatures()).thenReturn(mock(TimestampedECDSASignatures.class));
when(request.getHeader()).thenReturn(header);
processor.syncRequestEventProcessor().process(BFTNode.random(), SyncRequest.create(header));
verify(syncResponseDispatcher, never()).dispatch(any(BFTNode.class), any());
}
use of com.radixdlt.ledger.DtoLedgerProof in project radixdlt by radixdlt.
the class RemoteSyncServiceTest method when_remote_sync_request__then_process_it.
@Test
public void when_remote_sync_request__then_process_it() {
SyncRequest request = mock(SyncRequest.class);
DtoLedgerProof header = mock(DtoLedgerProof.class);
when(header.getOpaque()).thenReturn(HashUtils.zero256());
when(header.getLedgerHeader()).thenReturn(mock(LedgerHeader.class));
when(header.getSignatures()).thenReturn(mock(TimestampedECDSASignatures.class));
when(request.getHeader()).thenReturn(header);
BFTNode node = mock(BFTNode.class);
VerifiedTxnsAndProof verifiedTxnsAndProof = mock(VerifiedTxnsAndProof.class);
LedgerProof verifiedHeader = mock(LedgerProof.class);
when(verifiedHeader.toDto()).thenReturn(header);
when(verifiedTxnsAndProof.getProof()).thenReturn(verifiedHeader);
when(reader.getNextCommittedTxns(any())).thenReturn(verifiedTxnsAndProof);
processor.syncRequestEventProcessor().process(node, SyncRequest.create(header));
verify(syncResponseDispatcher, times(1)).dispatch(eq(node), any());
}
Aggregations