Search in sources :

Example 1 with DtoLedgerProof

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);
    }
}
Also used : LedgerProof(com.radixdlt.hotstuff.LedgerProof) DtoLedgerProof(com.radixdlt.ledger.DtoLedgerProof) REProcessedTxn(com.radixdlt.constraintmachine.REProcessedTxn) Txn(com.radixdlt.atom.Txn) IOException(java.io.IOException) Transaction(com.sleepycat.je.Transaction)

Example 2 with DtoLedgerProof

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);
}
Also used : TimestampedECDSASignatures(com.radixdlt.hotstuff.TimestampedECDSASignatures) DtoLedgerProof(com.radixdlt.ledger.DtoLedgerProof) DtoTxnsAndProof(com.radixdlt.ledger.DtoTxnsAndProof) BFTValidatorSet(com.radixdlt.hotstuff.bft.BFTValidatorSet) Before(org.junit.Before)

Example 3 with DtoLedgerProof

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()));
}
Also used : DtoLedgerProof(com.radixdlt.ledger.DtoLedgerProof) RemoteEvent(com.radixdlt.environment.rx.RemoteEvent) Test(org.junit.Test)

Example 4 with DtoLedgerProof

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());
}
Also used : TimestampedECDSASignatures(com.radixdlt.hotstuff.TimestampedECDSASignatures) DtoLedgerProof(com.radixdlt.ledger.DtoLedgerProof) LedgerHeader(com.radixdlt.hotstuff.LedgerHeader) BFTNode(com.radixdlt.hotstuff.bft.BFTNode) SyncRequest(com.radixdlt.sync.messages.remote.SyncRequest) Test(org.junit.Test)

Example 5 with DtoLedgerProof

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());
}
Also used : TimestampedECDSASignatures(com.radixdlt.hotstuff.TimestampedECDSASignatures) DtoLedgerProof(com.radixdlt.ledger.DtoLedgerProof) LedgerHeader(com.radixdlt.hotstuff.LedgerHeader) BFTNode(com.radixdlt.hotstuff.bft.BFTNode) SyncRequest(com.radixdlt.sync.messages.remote.SyncRequest) VerifiedTxnsAndProof(com.radixdlt.ledger.VerifiedTxnsAndProof) LedgerProof(com.radixdlt.hotstuff.LedgerProof) DtoLedgerProof(com.radixdlt.ledger.DtoLedgerProof) Test(org.junit.Test)

Aggregations

DtoLedgerProof (com.radixdlt.ledger.DtoLedgerProof)6 TimestampedECDSASignatures (com.radixdlt.hotstuff.TimestampedECDSASignatures)4 Test (org.junit.Test)4 LedgerHeader (com.radixdlt.hotstuff.LedgerHeader)3 BFTNode (com.radixdlt.hotstuff.bft.BFTNode)3 LedgerProof (com.radixdlt.hotstuff.LedgerProof)2 SyncRequest (com.radixdlt.sync.messages.remote.SyncRequest)2 Txn (com.radixdlt.atom.Txn)1 REProcessedTxn (com.radixdlt.constraintmachine.REProcessedTxn)1 RemoteEvent (com.radixdlt.environment.rx.RemoteEvent)1 BFTValidatorSet (com.radixdlt.hotstuff.bft.BFTValidatorSet)1 DtoTxnsAndProof (com.radixdlt.ledger.DtoTxnsAndProof)1 VerifiedTxnsAndProof (com.radixdlt.ledger.VerifiedTxnsAndProof)1 Transaction (com.sleepycat.je.Transaction)1 IOException (java.io.IOException)1 Before (org.junit.Before)1