Skip to content

Commit

Permalink
Reveal pre-images on a timer
Browse files Browse the repository at this point in the history
The having pre-image  is currently being checked in FullNode.putTransaction
 to see if pre-image is required.
It's call location is inefficient And that function is only needed by the validator.
Therefore, it is checked using a timer that is called periodically.
  • Loading branch information
TrustHenry committed May 26, 2020
1 parent 6001ec3 commit aad5900
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 25 deletions.
10 changes: 0 additions & 10 deletions source/agora/node/FullNode.d
Original file line number Diff line number Diff line change
Expand Up @@ -217,16 +217,6 @@ public class FullNode : API
this.network.gossipTransaction(tx);
this.onAcceptedTransaction();
}

if (this.enroll_man.needRevealPreimage(this.ledger.getBlockHeight()))
{
PreImageInfo preimage;
if (this.enroll_man.getNextPreimage(preimage))
{
this.receivePreimage(preimage);
this.enroll_man.increaseNextRevealHeight();
}
}
}

/// GET: /has_transaction_hash
Expand Down
24 changes: 24 additions & 0 deletions source/agora/node/Validator.d
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import scpd.types.Stellar_SCP;

import ocean.util.log.Logger;

import core.time;

mixin AddLogger!();

/*******************************************************************************
Expand Down Expand Up @@ -81,6 +83,8 @@ public class Validator : FullNode, API

log.info("Doing network discovery..");
this.network.discover(required_peer_keys);
// call checkRevealPreimage periodically every 10 seconds
this.taskman.timer(10.seconds, &this.checkRevealPreimage, Periodic.Yes);
this.network.startPeriodicCatchup(this.ledger, &this.nominator.isNominating);
});
}
Expand Down Expand Up @@ -171,4 +175,24 @@ public class Validator : FullNode, API
foreach (sub_conf; quorum_conf.quorums)
buildRequiredKeys(filter, sub_conf, nodes);
}

/***************************************************************************
Periodically check for pre-images revelation
Increase the next reveal height by revelation period if necessary.
***************************************************************************/

private void checkRevealPreimage () @safe
{
if (!this.enroll_man.needRevealPreimage(this.ledger.getBlockHeight()))
return;

PreImageInfo preimage;
if (this.enroll_man.getNextPreimage(preimage))
{
this.receivePreimage(preimage);
this.enroll_man.increaseNextRevealHeight();
}
}
}
17 changes: 2 additions & 15 deletions source/agora/test/EnrollmentManager.d
Original file line number Diff line number Diff line change
Expand Up @@ -89,21 +89,8 @@ unittest
txs2.each!(tx => node_1.putTransaction(tx));
containSameBlocks(nodes, 2).retryFor(8.seconds);

// Currently a new transaction needs to be sent to trigger
// the reveal of a pre-image
// See https://github.com/bpfkorea/agora/issues/582
Transaction tx =
{
TxType.Payment,
[Input(hashFull(txs2[0]), 0)],
[Output(Amount(100), pubkey_1)]
};
auto signature = gen_key_pair.secret.sign(hashFull(tx)[]);
tx.inputs[0].signature = signature;
node_1.putTransaction(tx);

// check if nodes have a pre-image newly sent
// during creating transactions for the new block
// Check if nodes have a pre-image newly sent
// While the timer is running on the taskmanager
nodes.each!(node =>
retryFor(node.getPreimage(enroll.utxo_key) != PreImageInfo.init,
5.seconds));
Expand Down

0 comments on commit aad5900

Please sign in to comment.