Search in sources :

Example 1 with HashSigner

use of com.radixdlt.hotstuff.HashSigner in project radixdlt by radixdlt.

the class SafetyRulesTest method setup.

@Before
public void setup() {
    this.safetyState = mock(SafetyState.class);
    Hasher hasher = mock(Hasher.class);
    when(hasher.hash(any())).thenReturn(HashUtils.random256());
    when(hasher.hashBytes(any())).thenReturn(HashUtils.random256());
    HashSigner hashSigner = mock(HashSigner.class);
    when(hashSigner.sign(any(HashCode.class))).thenReturn(ECDSASignature.zeroSignature());
    final var hashVerifier = mock(HashVerifier.class);
    final var validatorSet = mock(BFTValidatorSet.class);
    this.safetyRules = new SafetyRules(mock(BFTNode.class), safetyState, mock(PersistentSafetyStateStore.class), hasher, hashSigner, hashVerifier, validatorSet);
}
Also used : Hasher(com.radixdlt.crypto.Hasher) HashCode(com.google.common.hash.HashCode) HashSigner(com.radixdlt.hotstuff.HashSigner) Before(org.junit.Before)

Example 2 with HashSigner

use of com.radixdlt.hotstuff.HashSigner in project radixdlt by radixdlt.

the class SafetyRulesTest method when_vote_with_qc_on_different_locked_view__then_exception_is_thrown.

@Test
public void when_vote_with_qc_on_different_locked_view__then_exception_is_thrown() {
    Hasher hasher = mock(Hasher.class);
    when(hasher.hash(any())).thenReturn(mock(HashCode.class));
    HashSigner hashSigner = mock(HashSigner.class);
    when(hashSigner.sign(any(HashCode.class))).thenReturn(ECDSASignature.zeroSignature());
    Vote lastVote = mock(Vote.class);
    when(lastVote.getView()).thenReturn(View.of(1));
    final var hashVerifier = mock(HashVerifier.class);
    final var validatorSet = mock(BFTValidatorSet.class);
    final var safetyRules = new SafetyRules(BFTNode.random(), new SafetyState(View.of(2), Optional.of(lastVote)), mock(PersistentSafetyStateStore.class), hasher, hashSigner, hashVerifier, validatorSet);
    VerifiedVertex vertex = mock(VerifiedVertex.class);
    when(vertex.getView()).thenReturn(View.of(3));
    BFTHeader parent = mock(BFTHeader.class);
    when(parent.getView()).thenReturn(View.of(0));
    when(vertex.getParentHeader()).thenReturn(parent);
    assertThat(safetyRules.voteFor(vertex, mock(BFTHeader.class), 0L, mock(HighQC.class))).isEmpty();
}
Also used : VerifiedVertex(com.radixdlt.hotstuff.bft.VerifiedVertex) HighQC(com.radixdlt.hotstuff.HighQC) BFTHeader(com.radixdlt.hotstuff.BFTHeader) Hasher(com.radixdlt.crypto.Hasher) Vote(com.radixdlt.hotstuff.Vote) HashCode(com.google.common.hash.HashCode) HashSigner(com.radixdlt.hotstuff.HashSigner) Test(org.junit.Test)

Example 3 with HashSigner

use of com.radixdlt.hotstuff.HashSigner in project radixdlt by radixdlt.

the class SimulationNodes method createBFTModule.

private Module createBFTModule(ECKeyPair self) {
    Module module = Modules.combine(new AbstractModule() {

        @Provides
        @Self
        private BFTNode self() {
            return BFTNode.create(self.getPublicKey());
        }

        @Provides
        @Self
        private ECPublicKey key() {
            return self.getPublicKey();
        }

        @Provides
        private ECKeyPair keyPair() {
            return self;
        }

        @Provides
        @LocalSigner
        HashSigner hashSigner() {
            return self::sign;
        }
    }, new NodeNetworkMessagesModule(underlyingNetwork), baseModule);
    // can break network behavior if incorrect modules are used
    if (overrideModules.containsKey(self.getPublicKey())) {
        final var nodeOverrideModules = overrideModules.get(self.getPublicKey());
        module = Modules.override(module).with(nodeOverrideModules);
    }
    return module;
}
Also used : BFTNode(com.radixdlt.hotstuff.bft.BFTNode) ECPublicKey(com.radixdlt.crypto.ECPublicKey) LocalSigner(com.radixdlt.qualifier.LocalSigner) NodeNetworkMessagesModule(com.radixdlt.harness.simulation.NodeNetworkMessagesModule) ECKeyPair(com.radixdlt.crypto.ECKeyPair) HashSigner(com.radixdlt.hotstuff.HashSigner) Self(com.radixdlt.hotstuff.bft.Self) Module(com.google.inject.Module) NodeNetworkMessagesModule(com.radixdlt.harness.simulation.NodeNetworkMessagesModule) AbstractModule(com.google.inject.AbstractModule) Provides(com.google.inject.Provides) AbstractModule(com.google.inject.AbstractModule)

Aggregations

HashSigner (com.radixdlt.hotstuff.HashSigner)3 HashCode (com.google.common.hash.HashCode)2 Hasher (com.radixdlt.crypto.Hasher)2 AbstractModule (com.google.inject.AbstractModule)1 Module (com.google.inject.Module)1 Provides (com.google.inject.Provides)1 ECKeyPair (com.radixdlt.crypto.ECKeyPair)1 ECPublicKey (com.radixdlt.crypto.ECPublicKey)1 NodeNetworkMessagesModule (com.radixdlt.harness.simulation.NodeNetworkMessagesModule)1 BFTHeader (com.radixdlt.hotstuff.BFTHeader)1 HighQC (com.radixdlt.hotstuff.HighQC)1 Vote (com.radixdlt.hotstuff.Vote)1 BFTNode (com.radixdlt.hotstuff.bft.BFTNode)1 Self (com.radixdlt.hotstuff.bft.Self)1 VerifiedVertex (com.radixdlt.hotstuff.bft.VerifiedVertex)1 LocalSigner (com.radixdlt.qualifier.LocalSigner)1 Before (org.junit.Before)1 Test (org.junit.Test)1