public classBlockChain {
private classBlockNode {
Declares fields b, parent, children, height, uPool;
publicBlockNode(Blockb, BlockNodeparent, UTXOPooluPool) {
Assign b to the b field of own instance;
Assign parent to the parent field of own instance;
Create a children instance;
Assign uPool to the uPool field of own instance;
if (!parent is null) {
Assign parent.height + 1 to the height;
Add own instance to the end of parent.children;
} else {
Assign 1 to the height;
}
}
publicUTXOPoolgetUTXOPoolCopy() {
return new instance with the argument value uPool;
}
}
Declares fields blockChain, maxHeightNode, txPool;
Initializes the class constant CUT_OFF_AGE is 10;
/** create an empty block chain with just a genesis block. Assume {@code genesisBlock} is a valid block */
publicBlockChain(BlockgenesisBlock) {
Create a blockChain instance;
Create a utxoPool instance;
Add a coinbase transaction to the UTXO pool;
Initializes the field genesisNode with the argument values genesisBlock, null utxoPool;
Store the pair of genesisBlock hash and genesisNode in the blockchain;
Create a txPool instance;
Assign genesisNode to the maxHeightNode;
}
/** Get the maximum height block */
publicBlockgetMaxHeightBlock() {
return the block of maxHeightNode;
}
/** Get the UTXOPool for mining a new block on top of max height block */
publicUTXOPoolgetMaxHeightUTXOPool() {
return the UTXO pool of maxHeightNode;
}
/** Get the transaction pool to mine a new block */
publicTransactionPoolgetTransactionPool() {
return the transaction pool;
}
/** Add {@code block} to the block chain if it is valid */
/** Return true if block is successfully added */
publicbooleanaddBlock(Blockblock) {
Initializes the prevBlockHash is getPrevBlockHash() of block;
if (prevBlockHash is null)
returnfalse;
Initializes the field parentBlockNode is BlockNode corresponding to the prevBlockHash of blockChain;
if (parentBlockNode is null) {
returnfalse;
}
/** Transaction validity check */
Initializes the field handler with the argument value UTXO pool of parentBlockNode;
Initializes the field txs is the transaction of block;
Initializes the field validTxs is the valid transaction set in txs;
if (!validTxs.length is txs.length) {
returnfalse;
}
/** Block validity check*/
Initializes the field proposedHeight is parentBlockNode.height + 1;
if (proposedHeight <= maxHeightNode.height - CUT_OFF_AGE) {
returnfalse;
}
Initializes the field utxoPool is the UTXO pool of handler;
Add a coinbase transaction to the UTXO pool;
Initializes the field node with the argument values block, parentBlockNode, utxoPool;
Store the pair of block hash and node in the blockchain;
if (proposedHeight > maxHeightNode.height) {
Assign node to the maxHeightNode;
}
returntrue;
}
/** Add a transaction to the transaction pool */
publicvoidaddTransaction(Transactiontx) {
Add a tx to the transaction pool;
}
}
まず, ネットワーク内のノードには, Compliant (善良) と Malicious (悪意) の2種類があるとします. 「信頼」とは, ネットワークが有向ランダムグラフで表され, 各エッジがノード間の信頼関係を表しているという意味です. 例えば, A → B のエッジがある場合, ノード B はノード A が伝搬したトランザクションをリッスンしていることを意味し, B は A のフォロワーであり, A は B のフォロイーであると言います. もちろん善良ノードと悪意のあるノードには信頼関係が成り立たちません.
Tests for this assignment involve your submitted miner competing with a number of different types of malicious miners
Running test with parameters: numNodes = 100, p_graph = 0.1, p_malicious = 0.3, p_txDistribution = 0.01, numRounds = 10
On average 44 out of 72 of nodes reach consensus
Running test with parameters: numNodes = 100, p_graph = 0.1, p_malicious = 0.3, p_txDistribution = 0.05, numRounds = 10
On average 61 out of 72 of nodes reach consensus
Running test with parameters: numNodes = 100, p_graph = 0.1, p_malicious = 0.45, p_txDistribution = 0.01, numRounds = 10
On average 33 out of 58 of nodes reach consensus
Running test with parameters: numNodes = 100, p_graph = 0.1, p_malicious = 0.45, p_txDistribution = 0.05, numRounds = 10
On average 42 out of 58 of nodes reach consensus
Running test with parameters: numNodes = 100, p_graph = 0.2, p_malicious = 0.3, p_txDistribution = 0.01, numRounds = 10
On average 69 out of 76 of nodes reach consensus
Running test with parameters: numNodes = 100, p_graph = 0.2, p_malicious = 0.3, p_txDistribution = 0.05, numRounds = 10
On average 74 out of 76 of nodes reach consensus
Running test with parameters: numNodes = 100, p_graph = 0.2, p_malicious = 0.45, p_txDistribution = 0.01, numRounds = 10
On average 41 out of 54 of nodes reach consensus
Running test with parameters: numNodes = 100, p_graph = 0.2, p_malicious = 0.45, p_txDistribution = 0.05, numRounds = 10
On average 49 out of 54 of nodes reach consensus