Skip to content
This repository has been archived by the owner on Jun 17, 2020. It is now read-only.

Commit

Permalink
Tweak arguments passed to GenesisTxValidator.getGenesisTx()
Browse files Browse the repository at this point in the history
The genesisTotalSupply argument is added, which earlier was fetched implicitly from
BsqState.

The blockHeight argument is removed, since it refers to the blockheight of the RawTx
argument, which also can be fetched from that object with .getBlockHeight().

Calling code in BsqParser.maybeAddGenesisTx() is updated to respect new call signature.
Since .maybeAddGenesisTx() does not need blockHeight anymore either, it is also dropped here
as well as in the callers in LiteNodeParser and FullNodeParser.
  • Loading branch information
chirhonul committed Aug 1, 2018
1 parent f6f6261 commit c08a574
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 14 deletions.
10 changes: 5 additions & 5 deletions src/main/java/bisq/core/dao/node/BsqParser.java
Expand Up @@ -67,14 +67,14 @@ public BsqParser(BlockValidator blockValidator,
///////////////////////////////////////////////////////////////////////////////////////////
// Protected
///////////////////////////////////////////////////////////////////////////////////////////

protected void maybeAddGenesisTx(RawBlock rawBlock, int blockHeight, Block block) {
protected void maybeAddGenesisTx(RawBlock rawBlock, Block block) {
// We don't use streams here as we want to break as soon we found the genesis
for (RawTx rawTx : rawBlock.getRawTxs()) {
Optional<Tx> optionalTx = GenesisTxValidator.getGenesisTx(bsqStateService.getGenesisTxId(),
Optional<Tx> optionalTx = GenesisTxValidator.getGenesisTx(
bsqStateService.getGenesisTxId(),
bsqStateService.getGenesisBlockHeight(),
rawTx,
blockHeight);
bsqStateService.getGenesisTotalSupply(),
rawTx);
if (optionalTx.isPresent()) {
Tx genesisTx = optionalTx.get();
block.getTxs().add(genesisTx);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/bisq/core/dao/node/full/FullNodeParser.java
Expand Up @@ -76,7 +76,7 @@ Block parseBlock(RawBlock rawBlock) throws BlockNotConnectingException {
if (blockValidator.isBlockNotAlreadyAdded(rawBlock))
bsqStateService.onNewBlockWithEmptyTxs(block);

maybeAddGenesisTx(rawBlock, blockHeight, block);
maybeAddGenesisTx(rawBlock, block);

// Worst case is that all txs in a block are depending on another, so only one get resolved at each iteration.
// Min tx size is 189 bytes (normally about 240 bytes), 1 MB can contain max. about 5300 txs (usually 2000).
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/bisq/core/dao/node/lite/LiteNodeParser.java
Expand Up @@ -64,7 +64,7 @@ void parseBlock(RawBlock rawBlock) throws BlockNotConnectingException {
if (blockValidator.isBlockNotAlreadyAdded(rawBlock))
bsqStateService.onNewBlockWithEmptyTxs(block);

maybeAddGenesisTx(rawBlock, blockHeight, block);
maybeAddGenesisTx(rawBlock, block);

// recursiveFindBsqTxs(block, rawBlock.getRawTxs(), 0, 10000);
parseBsqTxs(block, rawBlock.getRawTxs());
Expand Down
Expand Up @@ -17,29 +17,27 @@

package bisq.core.dao.node.validation;

import bisq.core.dao.state.BsqState;
import bisq.core.dao.state.blockchain.RawTx;
import bisq.core.dao.state.blockchain.Tx;
import bisq.core.dao.state.blockchain.TxOutput;
import bisq.core.dao.state.blockchain.TxOutputType;
import bisq.core.dao.state.blockchain.TxType;

import org.bitcoinj.core.Coin;
import java.util.Optional;

/**
* Verifies if a given transaction is a BSQ genesis transaction.
*/
public class GenesisTxValidator {
public static Optional<Tx> getGenesisTx(String genesisTxId, int genesisBlockHeight, RawTx rawTx, int blockHeight) {
boolean isGenesis = blockHeight == genesisBlockHeight &&
public static Optional<Tx> getGenesisTx(String genesisTxId, int genesisBlockHeight, Coin genesisTotalSupply, RawTx rawTx) {
boolean isGenesis = rawTx.getBlockHeight() == genesisBlockHeight &&
rawTx.getId().equals(genesisTxId);

if (!isGenesis)
return Optional.empty();

Tx tx = new Tx(rawTx);
tx.setTxType(TxType.GENESIS);
long availableInputValue = BsqState.getGenesisTotalSupply().getValue();
long availableInputValue = genesisTotalSupply.getValue();
for (int i = 0; i < tx.getTxOutputs().size(); ++i) {
TxOutput txOutput = tx.getTxOutputs().get(i);
long value = txOutput.getValue();
Expand All @@ -48,7 +46,6 @@ public static Optional<Tx> getGenesisTx(String genesisTxId, int genesisBlockHeig
throw new RuntimeException("Genesis tx is isValid");

availableInputValue -= value;

txOutput.setTxOutputType(TxOutputType.GENESIS_OUTPUT);
}

Expand Down

0 comments on commit c08a574

Please sign in to comment.