Skip to content

Commit

Permalink
Merge pull request #78 from nguyenphuminh/patch-0.27.1
Browse files Browse the repository at this point in the history
Make get_work better
  • Loading branch information
nguyenphuminh authored Oct 16, 2023
2 parents 4c3b60d + b3fb9e1 commit 37ff69e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/node/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ async function startServer(options) {
await blockDB.put(newBlock.blockNumber.toString(), Buffer.from(_message.data)); // Add block to chain
await bhashDB.put(newBlock.hash, numToBuffer(newBlock.blockNumber)); // Assign block number to the matching block hash

chainInfo.latestBlock = newBlock; // Update chain info
chainInfo.latestBlock = newBlock; // Update latest block cache

// Update the new transaction pool (remove all the transactions that are no longer valid).
chainInfo.transactionPool = await clearDepreciatedTxns(chainInfo, stateDB);
Expand Down Expand Up @@ -235,7 +235,7 @@ async function startServer(options) {
await changeState(block, stateDB, codeDB, ENABLE_LOGGING); // Transit state
}

chainInfo.latestBlock = block; // Update latest block.
chainInfo.latestBlock = block; // Update latest block cache

await updateDifficulty(block, chainInfo, blockDB); // Update difficulty.

Expand Down Expand Up @@ -492,7 +492,7 @@ async function mine(publicKey, ENABLE_LOGGING) {
await blockDB.put(result.blockNumber.toString(), Buffer.from(Block.serialize(result))); // Add block to chain
await bhashDB.put(result.hash, numToBuffer(result.blockNumber)); // Assign block number to the matching block hash

chainInfo.latestBlock = result; // Update chain info
chainInfo.latestBlock = result; // Update latest block cache

// Reward

Expand Down
8 changes: 3 additions & 5 deletions src/rpc/rpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,14 @@ function rpc(PORT, client, transactionHandler, keyPair, stateDB, blockDB, bhashD
break;

case "get_pubkey":
respond({ address: client.publicKey });
respond({ pubkey: client.publicKey });

break;

case "get_work":
const latestBlock = Block.deserialize([...await blockDB.get( Math.max(...(await blockDB.keys().all()).map(key => parseInt(key))).toString() )]);

respond({
hash: latestBlock.hash,
nonce: latestBlock.nonce
hash: client.chainInfo.latestBlock.hash,
nonce: client.chainInfo.latestBlock.nonce
});

break;
Expand Down

0 comments on commit 37ff69e

Please sign in to comment.