Skip to content

Commit

Permalink
Merge pull request #75 from bartdejonge1996/cleanup
Browse files Browse the repository at this point in the history
Cleanup
  • Loading branch information
Taeir authored Feb 2, 2018
2 parents a0539b4 + 0531940 commit 6765ada
Show file tree
Hide file tree
Showing 30 changed files with 377 additions and 496 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ public MainChain getMainChain() {
*/
public void finishTransactionSending() {
int nodeID = localStore.getOwnNode().getId();
//transactionSender.stop();
try {
transactionSender.waitUntilDone();
TrackerHelper.setRunning(nodeID, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,56 +22,6 @@ public class ProofConstructor {
private final Map<Node, List<Block>> toSend;
private final Proof proof;

/*
* The Problem:
* We want to send block A.
* We have committed block B.
* With metaknowledge, we can translate this to a list of blocks that need to be sent.
*
* From all these blocks, we have to determine "what is the last block of each node that needs to be sent."
* This is "loop over the blocks, loop over the sources of transactions (recursively):
*
* Block A
* Block B
* Node sender
* Node receiver
* List<Block> ownBlocks = MetaKnowledge.determineBlocks(sender, B)
* processBlocks(sender, ownBlocks)
* Map<Node, List<Block>> toSend
* Map<Node, Set<Integer>> alreadyChecked
*
* processBlocks(Node owner, List<Block> blocks):
* //newlyAdded is the list of all the blocks that were added (not already present) (HAS TO BE ORDERED)
* List<Block> newlyAdded = toSend.addAll(owner, blocks)
* for (Block b : newlyAdded) {
* alreadyChecked.add(owner, b.getNumber())
* for (Transaction t : b.getTransactions()) {
* processSources(t)
* }
* }
*
* processSources(Transaction t):
* for (Transaction s : t.getSource())
* Node owner = s.getOwner();
* //Skip all sources in genesis blocks, our own blocks or in receiver blocks
* if (owner == null || owner == sender || owner == receiver) continue;
*
* Block b = s.getBlock()
* //Skip all blocks that were already checked
* if (b.getNumber() in alreadyChecked.get(owner)) continue;
*
* Block bCom = the first committed block at or after b
* if (bCom.getNumber() in alreadyChecked.get(owner)) continue;
*
* List<Block> blocksOfSource = MetaKnowledge.determineBlocks(owner, bCom)
* if (blocksOfSource is empty) {
* alreadyChecked.addAll(owner, 0 up to (inclusive) bCom.getNumber())
* continue;
* }
*
* processBlocks(owner, blocksOfSource)
*/

/**
* @param mainTransaction - the transaction to construct the proof for
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import nl.tudelft.blockchain.scaleoutdistributedledger.model.OwnNode;
import nl.tudelft.blockchain.scaleoutdistributedledger.simulation.Simulation;
import nl.tudelft.blockchain.scaleoutdistributedledger.simulation.tendermint.TendermintHelper;
import nl.tudelft.blockchain.scaleoutdistributedledger.simulation.transactionpattern.RandomTransactionPattern;
import nl.tudelft.blockchain.scaleoutdistributedledger.simulation.transactionpattern.ITransactionPattern;
import nl.tudelft.blockchain.scaleoutdistributedledger.simulation.transactionpattern.UniformRandomTransactionPattern;
import nl.tudelft.blockchain.scaleoutdistributedledger.utils.Log;
import nl.tudelft.blockchain.scaleoutdistributedledger.utils.Utils;
Expand Down Expand Up @@ -34,18 +34,22 @@ public final class SimulationMain {
//Whether this main is the master coordinator of the simulation
//Note that the master should always be started first
public static final boolean IS_MASTER = true;
//The duration of the simulation in seconds. Only has an effect when IS_MASTER == true.
//The duration of the simulation in seconds.
public static final int SIMULATION_DURATION = 600;
// Maximum number of blocks waiting to be sent (no new transaction created in the mean time
//Maximum number of blocks waiting to be sent (no new transaction will be created in the mean time)
public static final int MAX_BLOCKS_PENDING = 50;
// The initial delay in milliseconds to wait before checking for the first time.
//The initial delay in milliseconds to wait before checking what blocks can be sent.
public static final long INITIAL_SENDING_DELAY = 5000;
// The time in milliseconds to wait before checking again.
//The time in milliseconds between send checks.
public static final long SENDING_WAIT_TIME = 5000;
// The number of blocks (with the same or higher block number) that need to be committed before we send a certain block.
//The number of blocks (with the same or higher block number) that need to be committed before we send a certain block.
public static final int REQUIRED_COMMITS = 2;
// The number of transactions that are registered in one batch.
public static final int REGISTER_TRANSACTIONS_EVERY = 10;
//The transaction pattern that is used.
public static final ITransactionPattern TRANSACTION_PATTERN = new UniformRandomTransactionPattern(10, 20, 100, 200, 10);
//The initial amount of money each node has.
public static final long INITIAL_MONEY = 1000000;

private SimulationMain() {}

Expand Down Expand Up @@ -76,9 +80,8 @@ public static void main(String[] args) throws Exception {
// --- PHASE 2: all nodes registered, so create genesis block and genesis.json files ---

//update nodes from the tracker
Map<Integer, Node> nodes = new HashMap<>(TOTAL_NODES_NUMBER);
TrackerHelper.updateNodes(nodes, null);
final Block genesisBlock = TendermintHelper.generateGenesisBlock(1000000, nodes);
Map<Integer, Node> nodes = TrackerHelper.getNodes();
Block genesisBlock = TendermintHelper.generateGenesisBlock(INITIAL_MONEY, nodes);

//generate genesis.json for all local nodes
TendermintHelper.generateGenesisFiles(new Date(),
Expand All @@ -88,10 +91,7 @@ public static void main(String[] args) throws Exception {

// --- PHASE 3: start the actual simulation ---
Simulation simulation = new Simulation(IS_MASTER);

RandomTransactionPattern rtp = new UniformRandomTransactionPattern(10, 20, 100, 200, 10);
// rtp.setSeed(1);
simulation.setTransactionPattern(rtp);
simulation.setTransactionPattern(TRANSACTION_PATTERN);
simulation.runNodesLocally(nodes, ownNodes, genesisBlock, nodeToKeyPair);

// Wait for all nodes to have initialized
Expand All @@ -104,13 +104,9 @@ public static void main(String[] args) throws Exception {


// --- PHASE 4: stop the simulation ---
Thread.sleep(SIMULATION_DURATION * 1000);

if (IS_MASTER) {
Thread.sleep(SIMULATION_DURATION * 1000);
}

// Wait for all the other nodes to stop

//Stop the simulation and wait for nodes to stop.
simulation.stop();
waitForStop();

Expand Down
Loading

0 comments on commit 6765ada

Please sign in to comment.