/** * @return the height of the best known chain, convenience for <tt>getChainHead().getHeight()</tt>. */ public final int getBestChainHeight() { return getChainHead().getHeight(); }
/** * @return the height of the best known chain, convenience for <tt>getChainHead().getHeight()</tt>. */ public final int getBestChainHeight() { return getChainHead().getHeight(); }
/** * @return the height of the best known chain, convenience for <tt>getChainHead().getHeight()</tt>. */ public final int getBestChainHeight() { return getChainHead().getHeight(); }
/** * @return the height of the best known chain, convenience for <tt>getChainHead().getHeight()</tt>. */ public final int getBestChainHeight() { return getChainHead().getHeight(); }
void cleanTransactionLocksList() { //if(chainActive.Tip() == NULL) return; if(blockChain.getChainHead() == null) return; //std::map<uint256, CTransactionLock>::iterator it = mapTxLocks.begin(); Iterator<Map.Entry<Sha256Hash, TransactionLock>> it = mapTxLocks.entrySet().iterator(); while(it.hasNext()) { Map.Entry<Sha256Hash, TransactionLock> tl = it.next(); if(Utils.currentTimeSeconds() > tl.getValue().expiration){ //keep them for an hour log.info("Removing old transaction lock {}", tl.getValue().txHash.toString()); if(mapLockRequestAccepted.containsKey(tl.getValue().txHash)){ Transaction tx = mapLockRequestAccepted.get(tl.getValue().txHash); //BOOST_FOREACH(const CTxIn& in, tx.vin) for(TransactionInput in : tx.getInputs()) mapLockedOutpoints.remove(in.getOutpoint()); mapLockRequestAccepted.remove(tl.getValue().txHash); mapLockRequestRejected.remove(tl.getValue().txHash); //BOOST_FOREACH(CConsensusVote& v, it->second.vecConsensusVotes) for(TransactionLockVote v : tl.getValue().vecConsensusVotes) mapTxLockVotes.remove(v.getHash()); //Remove transaction confidence information, after 1 hour this should be a regular transaction //tx.getConfidence().setIX(false); //tx.getConfidence().setConsensusVotes(0); } it.remove(); } else { } } }
/** * When downloading the block chain, the bodies will be skipped for blocks created before the given date. Any * transactions relevant to the wallet will therefore not be found, but if you know your wallet has no such * transactions it doesn't matter and can save a lot of bandwidth and processing time. Note that the times of blocks * isn't known until their headers are available and they are requested in chunks, so some headers may be downloaded * twice using this scheme, but this optimization can still be a large win for newly created wallets. * * @param secondsSinceEpoch Time in seconds since the epoch or 0 to reset to always downloading block bodies. */ public void setDownloadParameters(long secondsSinceEpoch, boolean useFilteredBlocks) { lock.lock(); try { if (secondsSinceEpoch == 0) { fastCatchupTimeSecs = params.getGenesisBlock().getTimeSeconds(); downloadBlockBodies = true; } else { fastCatchupTimeSecs = secondsSinceEpoch; // If the given time is before the current chains head block time, then this has no effect (we already // downloaded everything we need). if (blockChain != null && fastCatchupTimeSecs > blockChain.getChainHead().getHeader().getTimeSeconds()) downloadBlockBodies = false; } this.useFilteredBlocks = useFilteredBlocks; } finally { lock.unlock(); } }
/** * When downloading the block chain, the bodies will be skipped for blocks created before the given date. Any * transactions relevant to the wallet will therefore not be found, but if you know your wallet has no such * transactions it doesn't matter and can save a lot of bandwidth and processing time. Note that the times of blocks * isn't known until their headers are available and they are requested in chunks, so some headers may be downloaded * twice using this scheme, but this optimization can still be a large win for newly created wallets. * * @param secondsSinceEpoch Time in seconds since the epoch or 0 to reset to always downloading block bodies. */ public void setDownloadParameters(long secondsSinceEpoch, boolean useFilteredBlocks) { lock.lock(); try { if (secondsSinceEpoch == 0) { fastCatchupTimeSecs = params.getGenesisBlock().getTimeSeconds(); downloadBlockBodies = true; } else { fastCatchupTimeSecs = secondsSinceEpoch; // If the given time is before the current chains head block time, then this has no effect (we already // downloaded everything we need). if (blockChain != null && fastCatchupTimeSecs > blockChain.getChainHead().getHeader().getTimeSeconds()) downloadBlockBodies = false; } this.useFilteredBlocks = useFilteredBlocks; } finally { lock.unlock(); } }
/** * When downloading the block chain, the bodies will be skipped for blocks created before the given date. Any * transactions relevant to the wallet will therefore not be found, but if you know your wallet has no such * transactions it doesn't matter and can save a lot of bandwidth and processing time. Note that the times of blocks * isn't known until their headers are available and they are requested in chunks, so some headers may be downloaded * twice using this scheme, but this optimization can still be a large win for newly created wallets. * * @param secondsSinceEpoch Time in seconds since the epoch or 0 to reset to always downloading block bodies. */ public void setDownloadParameters(long secondsSinceEpoch, boolean useFilteredBlocks) { lock.lock(); try { if (secondsSinceEpoch == 0) { fastCatchupTimeSecs = params.getGenesisBlock().getTimeSeconds(); downloadBlockBodies = true; } else { fastCatchupTimeSecs = secondsSinceEpoch; // If the given time is before the current chains head block time, then this has no effect (we already // downloaded everything we need). if (blockChain != null && fastCatchupTimeSecs > blockChain.getChainHead().getHeader().getTimeSeconds()) downloadBlockBodies = false; } this.useFilteredBlocks = useFilteredBlocks; } finally { lock.unlock(); } }
/** * When downloading the block chain, the bodies will be skipped for blocks created before the given date. Any * transactions relevant to the wallet will therefore not be found, but if you know your wallet has no such * transactions it doesn't matter and can save a lot of bandwidth and processing time. Note that the times of blocks * isn't known until their headers are available and they are requested in chunks, so some headers may be downloaded * twice using this scheme, but this optimization can still be a large win for newly created wallets. * * @param secondsSinceEpoch Time in seconds since the epoch or 0 to reset to always downloading block bodies. */ public void setDownloadParameters(long secondsSinceEpoch, boolean useFilteredBlocks) { lock.lock(); try { if (secondsSinceEpoch == 0) { fastCatchupTimeSecs = params.getGenesisBlock().getTimeSeconds(); downloadBlockBodies = true; } else { fastCatchupTimeSecs = secondsSinceEpoch; // If the given time is before the current chains head block time, then this has no effect (we already // downloaded everything we need). if (blockChain != null && fastCatchupTimeSecs > blockChain.getChainHead().getHeader().getTimeSeconds()) downloadBlockBodies = false; } this.useFilteredBlocks = useFilteredBlocks; } finally { lock.unlock(); } }
/** * Add a wallet to the BlockChain. Note that the wallet will be unaffected by any blocks received while it * was not part of this BlockChain. This method is useful if the wallet has just been created, and its keys * have never been in use, or if the wallet has been loaded along with the BlockChain. Note that adding multiple * wallets is not well tested! */ public final void addWallet(Wallet wallet) { addNewBestBlockListener(Threading.SAME_THREAD, wallet); addReorganizeListener(Threading.SAME_THREAD, wallet); addTransactionReceivedListener(Threading.SAME_THREAD, wallet); int walletHeight = wallet.getLastBlockSeenHeight(); int chainHeight = getBestChainHeight(); if (walletHeight != chainHeight) { log.warn("Wallet/chain height mismatch: {} vs {}", walletHeight, chainHeight); log.warn("Hashes: {} vs {}", wallet.getLastBlockSeenHash(), getChainHead().getHeader().getHash()); // This special case happens when the VM crashes because of a transaction received. It causes the updated // block store to persist, but not the wallet. In order to fix the issue, we roll back the block store to // the wallet height to make it look like as if the block has never been received. if (walletHeight < chainHeight && walletHeight > 0) { try { rollbackBlockStore(walletHeight); log.info("Rolled back block store to height {}.", walletHeight); } catch (BlockStoreException x) { log.warn("Rollback of block store failed, continuing with mismatched heights. This can happen due to a replay."); } } } }
/** * Add a wallet to the BlockChain. Note that the wallet will be unaffected by any blocks received while it * was not part of this BlockChain. This method is useful if the wallet has just been created, and its keys * have never been in use, or if the wallet has been loaded along with the BlockChain. Note that adding multiple * wallets is not well tested! */ public final void addWallet(Wallet wallet) { addNewBestBlockListener(Threading.SAME_THREAD, wallet); addReorganizeListener(Threading.SAME_THREAD, wallet); addTransactionReceivedListener(Threading.SAME_THREAD, wallet); int walletHeight = wallet.getLastBlockSeenHeight(); int chainHeight = getBestChainHeight(); if (walletHeight != chainHeight) { log.warn("Wallet/chain height mismatch: {} vs {}", walletHeight, chainHeight); log.warn("Hashes: {} vs {}", wallet.getLastBlockSeenHash(), getChainHead().getHeader().getHash()); // This special case happens when the VM crashes because of a transaction received. It causes the updated // block store to persist, but not the wallet. In order to fix the issue, we roll back the block store to // the wallet height to make it look like as if the block has never been received. if (walletHeight < chainHeight && walletHeight > 0) { try { rollbackBlockStore(walletHeight); log.info("Rolled back block store to height {}.", walletHeight); } catch (BlockStoreException x) { log.warn("Rollback of block store failed, continuing with mismatched heights. This can happen due to a replay."); } } } }
/** * Add a wallet to the BlockChain. Note that the wallet will be unaffected by any blocks received while it * was not part of this BlockChain. This method is useful if the wallet has just been created, and its keys * have never been in use, or if the wallet has been loaded along with the BlockChain. Note that adding multiple * wallets is not well tested! */ public final void addWallet(Wallet wallet) { addNewBestBlockListener(Threading.SAME_THREAD, wallet); addReorganizeListener(Threading.SAME_THREAD, wallet); addTransactionReceivedListener(Threading.SAME_THREAD, wallet); int walletHeight = wallet.getLastBlockSeenHeight(); int chainHeight = getBestChainHeight(); if (walletHeight != chainHeight) { log.warn("Wallet/chain height mismatch: {} vs {}", walletHeight, chainHeight); log.warn("Hashes: {} vs {}", wallet.getLastBlockSeenHash(), getChainHead().getHeader().getHash()); // This special case happens when the VM crashes because of a transaction received. It causes the updated // block store to persist, but not the wallet. In order to fix the issue, we roll back the block store to // the wallet height to make it look like as if the block has never been received. if (walletHeight < chainHeight && walletHeight > 0) { try { rollbackBlockStore(walletHeight); log.info("Rolled back block store to height {}.", walletHeight); } catch (BlockStoreException x) { log.warn("Rollback of block store failed, continuing with mismatched heights. This can happen due to a replay."); } } } }
/** * Add a wallet to the BlockChain. Note that the wallet will be unaffected by any blocks received while it * was not part of this BlockChain. This method is useful if the wallet has just been created, and its keys * have never been in use, or if the wallet has been loaded along with the BlockChain. Note that adding multiple * wallets is not well tested! */ public final void addWallet(Wallet wallet) { addNewBestBlockListener(Threading.SAME_THREAD, wallet); addReorganizeListener(Threading.SAME_THREAD, wallet); addTransactionReceivedListener(Threading.SAME_THREAD, wallet); int walletHeight = wallet.getLastBlockSeenHeight(); int chainHeight = getBestChainHeight(); if (walletHeight != chainHeight) { log.warn("Wallet/chain height mismatch: {} vs {}", walletHeight, chainHeight); log.warn("Hashes: {} vs {}", wallet.getLastBlockSeenHash(), getChainHead().getHeader().getHash()); // This special case happens when the VM crashes because of a transaction received. It causes the updated // block store to persist, but not the wallet. In order to fix the issue, we roll back the block store to // the wallet height to make it look like as if the block has never been received. if (walletHeight < chainHeight && walletHeight > 0) { try { rollbackBlockStore(walletHeight); log.info("Rolled back block store to height {}.", walletHeight); } catch (BlockStoreException x) { log.warn("Rollback of block store failed, continuing with mismatched heights. This can happen due to a replay."); } } } }
if (block.equals(getChainHead().getHeader())) { return true;
Sha256Hash _getBlockHash(long height) { try { StoredBlock head = blockChain.getChainHead(); BlockStore blockStore = blockChain.getBlockStore(); //long heightToFind = (height - 100) - ((height-100)%100); //If header is not stored, then return the tip //TODO: remove this or the whole function; if((head.getHeight() - 2050) > height) return null; StoredBlock cursor = head; while (cursor != null && cursor.getHeight() != (height-1)) { cursor = cursor.getPrev(blockStore); } return cursor != null ? cursor.getHeader().getHash() : null; } catch(BlockStoreException x) { return null; } }
if (block.equals(getChainHead().getHeader())) { return true;
if (block.equals(getChainHead().getHeader())) { return true;
if(blockChain.getChainHead().getHeight() < nBlockHeight) return -1; //Blockheight is above what the store has.
StoredBlock head = getChainHead(); final StoredBlock splitPoint = findSplit(newChainHead, head, blockStore); log.info("Re-organize after split at height {}", splitPoint.getHeight());
StoredBlock pindexBestHeader = blockChain.getChainHead();