Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small improvements/fixes #1728

Merged
merged 13 commits into from Sep 27, 2018
4 changes: 4 additions & 0 deletions common/src/main/java/bisq/common/app/Log.java
Expand Up @@ -88,6 +88,10 @@ public static void setup(String fileName) {
logbackLogger.addAppender(errorAppender);*/
}

public static void setCustomLogLevel(String pattern, Level logLevel) {
((Logger) LoggerFactory.getLogger(pattern)).setLevel(logLevel);
}

public static void traceCall() {
if (LoggerFactory.getLogger(Log.class).isTraceEnabled()) {
StackTraceElement stackTraceElement = new Throwable().getStackTrace()[1];
Expand Down
Expand Up @@ -67,4 +67,10 @@ public int getMessageVersion() {
return messageVersion;
}

@Override
public String toString() {
return "NetworkEnvelope{" +
"\n messageVersion=" + messageVersion +
"\n}";
}
}
2 changes: 1 addition & 1 deletion core/src/main/java/bisq/core/app/BisqEnvironment.java
Expand Up @@ -292,7 +292,7 @@ public BisqEnvironment(PropertySource commandLineProperties) {
"";
genesisBlockHeight = commandLineProperties.containsProperty(DaoOptionKeys.GENESIS_BLOCK_HEIGHT) ?
(String) commandLineProperties.getProperty(DaoOptionKeys.GENESIS_BLOCK_HEIGHT) :
"";
"-1";
daoActivated = commandLineProperties.containsProperty(DaoOptionKeys.DAO_ACTIVATED) ?
(String) commandLineProperties.getProperty(DaoOptionKeys.DAO_ACTIVATED) :
"";
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/bisq/core/app/BisqExecutable.java
Expand Up @@ -437,7 +437,7 @@ protected void customizeOptionParsing(OptionParser parser) {
description("Genesis transaction ID when not using the hard coded one", ""))
.withRequiredArg();
parser.accepts(DaoOptionKeys.GENESIS_BLOCK_HEIGHT,
description("Genesis transaction block height when not using the hard coded one", ""))
description("Genesis transaction block height when not using the hard coded one", -1))
.withRequiredArg();
parser.accepts(DaoOptionKeys.DAO_ACTIVATED,
description("Developer flag. If true it enables dao phase 2 features.", false))
Expand Down
10 changes: 9 additions & 1 deletion core/src/main/java/bisq/core/app/BisqSetup.java
Expand Up @@ -24,9 +24,9 @@
import bisq.core.arbitration.ArbitratorManager;
import bisq.core.arbitration.DisputeManager;
import bisq.core.btc.listeners.BalanceListener;
import bisq.core.btc.setup.WalletsSetup;
import bisq.core.btc.model.AddressEntry;
import bisq.core.btc.model.BalanceModel;
import bisq.core.btc.setup.WalletsSetup;
import bisq.core.btc.wallet.BtcWalletService;
import bisq.core.btc.wallet.WalletsManager;
import bisq.core.dao.DaoSetup;
Expand Down Expand Up @@ -61,6 +61,7 @@
import bisq.common.Timer;
import bisq.common.UserThread;
import bisq.common.app.DevEnv;
import bisq.common.app.Log;
import bisq.common.crypto.CryptoException;
import bisq.common.crypto.KeyRing;
import bisq.common.crypto.SealedAndSigned;
Expand Down Expand Up @@ -99,6 +100,8 @@
import java.util.function.BiConsumer;
import java.util.function.Consumer;

import ch.qos.logback.classic.Level;

import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -469,6 +472,11 @@ private void startP2pNetworkAndWallet() {
walletInitialized.addListener(walletInitializedListener);
else if (displayTorNetworkSettingsHandler != null)
displayTorNetworkSettingsHandler.accept(true);

log.info("Set log level for org.berndpruenster.netlayer classes to DEBUG to show more details for " +
"Tor network connection issues");
Log.setCustomLogLevel("org.berndpruenster.netlayer", Level.DEBUG);

}, STARTUP_TIMEOUT_MINUTES, TimeUnit.MINUTES);

p2pNetworkReady = p2PNetworkSetup.init(this::initWallet, displayTorNetworkSettingsHandler);
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/bisq/core/dao/DaoModule.java
Expand Up @@ -157,10 +157,10 @@ protected void configure() {
bind(IssuanceService.class).in(Singleton.class);

// Genesis
String genesisTxId = environment.getProperty(DaoOptionKeys.GENESIS_TX_ID, String.class, null);
String genesisTxId = environment.getProperty(DaoOptionKeys.GENESIS_TX_ID, String.class, "");
bind(String.class).annotatedWith(Names.named(DaoOptionKeys.GENESIS_TX_ID)).toInstance(genesisTxId);

Integer genesisBlockHeight = environment.getProperty(DaoOptionKeys.GENESIS_BLOCK_HEIGHT, Integer.class, 0);
Integer genesisBlockHeight = environment.getProperty(DaoOptionKeys.GENESIS_BLOCK_HEIGHT, Integer.class, -1);
bind(Integer.class).annotatedWith(Names.named(DaoOptionKeys.GENESIS_BLOCK_HEIGHT)).toInstance(genesisBlockHeight);

// Bonds
Expand Down
8 changes: 6 additions & 2 deletions core/src/main/java/bisq/core/dao/node/BsqNode.java
Expand Up @@ -155,7 +155,11 @@ protected void onP2PNetworkReady() {

@SuppressWarnings("WeakerAccess")
protected int getStartBlockHeight() {
final int startBlockHeight = Math.max(genesisBlockHeight, bsqStateService.getChainHeight());
int chainHeight = bsqStateService.getChainHeight();
int startBlockHeight = chainHeight;
if (chainHeight > genesisBlockHeight)
startBlockHeight = chainHeight + 1;

log.info("Start parse blocks:\n" +
" Start block height={}\n" +
" Genesis txId={}\n" +
Expand All @@ -164,7 +168,7 @@ protected int getStartBlockHeight() {
startBlockHeight,
genesisTxId,
genesisBlockHeight,
bsqStateService.getChainHeight());
chainHeight);

return startBlockHeight;
}
Expand Down
8 changes: 5 additions & 3 deletions core/src/main/java/bisq/core/dao/node/full/FullNode.java
Expand Up @@ -40,7 +40,7 @@
/**
* Main class for a full node which have Bitcoin Core with rpc running and does the blockchain lookup itself.
* It also provides the BSQ transactions to lite nodes on request and broadcasts new BSQ blocks.
*
* <p>
* TODO request p2p network data again after parsing is complete to be sure that in case we missed data during parsing
* we get it added.
*/
Expand Down Expand Up @@ -188,8 +188,8 @@ private void parseBlocksOnHeadHeight(int startBlockHeight, int chainHeadHeight)
parseBlocksIfNewBlockAvailable(chainHeadHeight);
}, throwable -> {
if (throwable instanceof BlockNotConnectingException) {
int blockHeightOfLastBlock = bsqStateService.getBlockHeightOfLastBlock();
requestChainHeadHeightAndParseBlocks(blockHeightOfLastBlock);
int startHeight = bsqStateService.getBlockHeightOfLastBlock() + 1;
requestChainHeadHeightAndParseBlocks(startHeight);
} else {
handleError(throwable);
}
Expand Down Expand Up @@ -232,6 +232,8 @@ private void parseBlock(int blockHeight, int chainHeadHeight,
} catch (BlockNotConnectingException e) {
errorHandler.accept(e);
}
} else {
log.info("Block was already added height=", rawBlock.getHeight());
}
},
errorHandler);
Expand Down
Expand Up @@ -95,7 +95,8 @@ public void onGetBlocksRequest(GetBlocksRequest getBlocksRequest, final Connecti
List<RawBlock> rawBlocks = blocks.stream().map(RawBlock::fromBlock).collect(Collectors.toList());
final GetBlocksResponse getBlocksResponse = new GetBlocksResponse(rawBlocks, getBlocksRequest.getNonce());
log.debug("getBlocksResponse " + getBlocksResponse.getRequestNonce());

log.info("Received getBlocksResponse from {} for blocks from height {}",
connection.getPeersNodeAddressOptional(), getBlocksRequest.getFromBlockHeight());
if (timeoutTimer == null) {
timeoutTimer = UserThread.runAfter(() -> { // setup before sending to avoid race conditions
String errorMessage = "A timeout occurred for getBlocksResponse:" + getBlocksResponse +
Expand All @@ -110,7 +111,7 @@ public void onGetBlocksRequest(GetBlocksRequest getBlocksRequest, final Connecti
@Override
public void onSuccess(Connection connection) {
if (!stopped) {
log.trace("Send DataResponse to {} succeeded. getBlocksResponse={}",
log.info("Send DataResponse to {} succeeded. getBlocksResponse={}",
connection.getPeersNodeAddressOptional(), getBlocksResponse);
cleanup();
listener.onComplete();
Expand Down
Expand Up @@ -139,7 +139,6 @@ public void addListener(Listener listener) {
}

public void requestBlocks(int startBlockHeight) {
Log.traceCall();
lastRequestedBlockHeight = startBlockHeight;
Optional<Connection> connectionToSeedNodeOptional = networkNode.getConfirmedConnections().stream()
.filter(peerManager::isSeedNode)
Expand Down Expand Up @@ -219,6 +218,7 @@ public void onAwakeFromStandby() {
@Override
public void onMessage(NetworkEnvelope networkEnvelope, Connection connection) {
if (networkEnvelope instanceof NewBlockBroadcastMessage) {
log.info("We received blocks from peer {}", connection.getPeersNodeAddressOptional());
listeners.forEach(listener -> listener.onNewBlockReceived((NewBlockBroadcastMessage) networkEnvelope));
}
}
Expand All @@ -239,7 +239,7 @@ private void requestBlocks(NodeAddress peersNodeAddress, int startBlockHeight) {
new RequestBlocksHandler.Listener() {
@Override
public void onComplete(GetBlocksResponse getBlocksResponse) {
log.trace("requestBlocksHandler of outbound connection complete. nodeAddress={}",
log.info("requestBlocksHandler of outbound connection complete. nodeAddress={}",
peersNodeAddress);
stopRetryTimer();

Expand Down Expand Up @@ -270,6 +270,7 @@ public void onFault(String errorMessage, @Nullable Connection connection) {
}
});
requestBlocksHandlerMap.put(key, requestBlocksHandler);
log.info("requestBlocks with startBlockHeight={} from peer {}", startBlockHeight, peersNodeAddress);
requestBlocksHandler.requestBlocks();
} else {
//TODO check with re-orgs
Expand Down
Expand Up @@ -126,14 +126,14 @@ public void requestBlocks() {
TIMEOUT);
}

log.debug("We send a {} to peer {}. ", getBlocksRequest.getClass().getSimpleName(), nodeAddress);
log.info("We send to peer {} a {}.", nodeAddress, getBlocksRequest);
networkNode.addMessageListener(this);
SettableFuture<Connection> future = networkNode.sendMessage(nodeAddress, getBlocksRequest);
Futures.addCallback(future, new FutureCallback<Connection>() {
@Override
public void onSuccess(Connection connection) {
if (!stopped) {
log.trace("Send " + getBlocksRequest + " to " + nodeAddress + " succeeded.");
log.info("Sending of GetBlocksRequest message to peer {} succeeded.", nodeAddress.getHostName());
} else {
log.trace("We have stopped already. We ignore that networkNode.sendMessage.onSuccess call." +
"Might be caused by an previous timeout.");
Expand Down Expand Up @@ -178,6 +178,7 @@ public void onMessage(NetworkEnvelope networkEnvelope, Connection connection) {
"RequestDataHandler.onMessage: connection.getPeersNodeAddressOptional() must be present " +
"at that moment");
cleanup();
log.info("We received from peer {} a {}", nodeAddress.getFullAddress(), getBlocksResponse);
listener.onComplete(getBlocksResponse);
} else {
log.warn("Nonce not matching. That can happen rarely if we get a response after a canceled " +
Expand Down
Expand Up @@ -32,11 +32,9 @@

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;

@EqualsAndHashCode(callSuper = true)
@Getter
@ToString
public final class GetBlocksRequest extends NetworkEnvelope implements DirectMessage, CapabilityRequiringPayload {
private final int fromBlockHeight;
private final int nonce;
Expand Down Expand Up @@ -75,4 +73,13 @@ public List<Integer> getRequiredCapabilities() {
Capabilities.Capability.DAO_FULL_NODE.ordinal()
));
}


@Override
public String toString() {
return "GetBlocksRequest{" +
"\n fromBlockHeight=" + fromBlockHeight +
",\n nonce=" + nonce +
"\n} " + super.toString();
}
}
Expand Up @@ -75,4 +75,13 @@ public static NetworkEnvelope fromProto(PB.GetBlocksResponse proto, int messageV
proto.getRequestNonce(),
messageVersion);
}


@Override
public String toString() {
return "GetBlocksResponse{" +
"\n blocks=" + blocks +
",\n requestNonce=" + requestNonce +
"\n} " + super.toString();
}
}
23 changes: 9 additions & 14 deletions core/src/main/java/bisq/core/dao/node/parser/TxParser.java
Expand Up @@ -372,22 +372,17 @@ private Optional<OpReturnType> getOptionalOpReturnType() {
// We want to be sure that the initial assumption of the opReturn type was matching the result after full
// validation.
Optional<OpReturnType> optionalOpReturnTypeCandidate = txOutputParser.getOptionalOpReturnTypeCandidate();
if (optionalOpReturnTypeCandidate.isPresent()) {
OpReturnType opReturnTypeCandidate = optionalOpReturnTypeCandidate.get();
Optional<OpReturnType> optionalVerifiedOpReturnType = txOutputParser.getOptionalVerifiedOpReturnType();
if (optionalVerifiedOpReturnType.isPresent()) {
OpReturnType verifiedOpReturnType = optionalVerifiedOpReturnType.get();
if (opReturnTypeCandidate == verifiedOpReturnType) {
return optionalVerifiedOpReturnType;
}
Optional<OpReturnType> optionalVerifiedOpReturnType = txOutputParser.getOptionalVerifiedOpReturnType();
if (optionalOpReturnTypeCandidate.isPresent() && optionalVerifiedOpReturnType.isPresent()) {
if (optionalOpReturnTypeCandidate.get() == optionalVerifiedOpReturnType.get()) {
return optionalVerifiedOpReturnType;
} else {
String msg = "We got a different opReturn type after validation as we expected initially. " +
"optionalOpReturnTypeCandidate=" + optionalOpReturnTypeCandidate +
", optionalVerifiedOpReturnType=" + txOutputParser.getOptionalVerifiedOpReturnType();
log.warn(msg);
}
}

String msg = "We got a different opReturn type after validation as we expected initially. " +
"optionalOpReturnTypeCandidate=" + optionalOpReturnTypeCandidate +
", optionalVerifiedOpReturnType=" + txOutputParser.getOptionalVerifiedOpReturnType();
log.error(msg);

} else {
String msg = "We got a tx without any valid BSQ output but with burned BSQ. " +
"Burned fee=" + remainingInputValue / 100D + " BSQ.";
Expand Down
10 changes: 4 additions & 6 deletions core/src/main/java/bisq/core/dao/state/GenesisTxInfo.java
Expand Up @@ -29,8 +29,6 @@
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

import javax.annotation.Nullable;


/**
* Encapsulate the genesis txId and height.
Expand Down Expand Up @@ -87,12 +85,12 @@ public class GenesisTxInfo {
///////////////////////////////////////////////////////////////////////////////////////////

@Inject
public GenesisTxInfo(@Nullable @Named(DaoOptionKeys.GENESIS_TX_ID) String genesisTxId,
@Named(DaoOptionKeys.GENESIS_BLOCK_HEIGHT) int genesisBlockHeight) {
public GenesisTxInfo(@Named(DaoOptionKeys.GENESIS_TX_ID) String genesisTxId,
@Named(DaoOptionKeys.GENESIS_BLOCK_HEIGHT) Integer genesisBlockHeight) {
BaseCurrencyNetwork baseCurrencyNetwork = BisqEnvironment.getBaseCurrencyNetwork();
boolean isMainnet = baseCurrencyNetwork.isMainnet();
boolean isTestnet = baseCurrencyNetwork.isTestnet();
if (genesisTxId != null && !genesisTxId.isEmpty()) {
if (!genesisTxId.isEmpty()) {
this.genesisTxId = genesisTxId;
} else if (isMainnet) {
this.genesisTxId = MAINNET_GENESIS_TX_ID;
Expand All @@ -102,7 +100,7 @@ public GenesisTxInfo(@Nullable @Named(DaoOptionKeys.GENESIS_TX_ID) String genesi
this.genesisTxId = "genesisTxId is undefined";
}

if (genesisBlockHeight != 0) {
if (genesisBlockHeight > -1) {
this.genesisBlockHeight = genesisBlockHeight;
} else if (isMainnet) {
this.genesisBlockHeight = MAINNET_GENESIS_BLOCK_HEIGHT;
Expand Down
5 changes: 2 additions & 3 deletions core/src/main/java/bisq/core/dao/state/SnapshotManager.java
Expand Up @@ -37,11 +37,10 @@

/**
* Manages snapshots of BsqState.
* // FIXME not working correctly anymore
*/
@Slf4j
public class SnapshotManager implements BsqStateListener {
private static final int SNAPSHOT_GRID = 11000;
private static final int SNAPSHOT_GRID = 100;

private final BsqState bsqState;
private final BsqStateService bsqStateService;
Expand Down Expand Up @@ -90,7 +89,7 @@ public void onParseTxsComplete(Block block) {
// Now we clone and keep it in memory for the next trigger
snapshotCandidate = bsqState.getClone();
// don't access cloned anymore with methods as locks are transient!
log.debug("Cloned new snapshotCandidate at height " + chainHeadHeight);
log.info("Cloned new snapshotCandidate at height " + chainHeadHeight);
}
}

Expand Down
12 changes: 9 additions & 3 deletions core/src/main/java/bisq/core/dao/state/blockchain/BaseBlock.java
Expand Up @@ -19,8 +19,11 @@

import io.bisq.generated.protobuffer.PB;

import java.util.Optional;

import lombok.Data;

import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;

/**
Expand All @@ -33,6 +36,7 @@ public abstract class BaseBlock {
protected final int height;
protected final long time; // in ms
protected final String hash;
@Nullable // in case of first block in the blockchain
protected final String previousBlockHash;

BaseBlock(int height, long time, String hash, String previousBlockHash) {
Expand All @@ -48,11 +52,13 @@ public abstract class BaseBlock {
///////////////////////////////////////////////////////////////////////////////////////////

PB.BaseBlock.Builder getBaseBlockBuilder() {
return PB.BaseBlock.newBuilder()
PB.BaseBlock.Builder builder = PB.BaseBlock.newBuilder()
.setHeight(height)
.setTime(time)
.setHash(hash)
.setPreviousBlockHash(previousBlockHash);
.setHash(hash);
Optional.ofNullable(previousBlockHash).ifPresent(builder::setPreviousBlockHash);
return builder;

}

@Override
Expand Down