forked from Qortal/qortal
BlockMinter (now under org.qortal.controller package) doesn't need full previous block, only previous block data
This commit is contained in:
parent
276c479a5f
commit
31bf388cab
@ -1,4 +1,4 @@
|
|||||||
package org.qortal.block;
|
package org.qortal.controller;
|
||||||
|
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -13,8 +13,9 @@ import org.apache.logging.log4j.LogManager;
|
|||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.qortal.account.Account;
|
import org.qortal.account.Account;
|
||||||
import org.qortal.account.PrivateKeyAccount;
|
import org.qortal.account.PrivateKeyAccount;
|
||||||
|
import org.qortal.block.Block;
|
||||||
import org.qortal.block.Block.ValidationResult;
|
import org.qortal.block.Block.ValidationResult;
|
||||||
import org.qortal.controller.Controller;
|
import org.qortal.block.BlockChain;
|
||||||
import org.qortal.data.account.MintingAccountData;
|
import org.qortal.data.account.MintingAccountData;
|
||||||
import org.qortal.data.account.RewardShareData;
|
import org.qortal.data.account.RewardShareData;
|
||||||
import org.qortal.data.block.BlockData;
|
import org.qortal.data.block.BlockData;
|
||||||
@ -60,7 +61,7 @@ public class BlockMinter extends Thread {
|
|||||||
List<TransactionData> unconfirmedTransactions = repository.getTransactionRepository().getUnconfirmedTransactions();
|
List<TransactionData> unconfirmedTransactions = repository.getTransactionRepository().getUnconfirmedTransactions();
|
||||||
|
|
||||||
for (TransactionData transactionData : unconfirmedTransactions) {
|
for (TransactionData transactionData : unconfirmedTransactions) {
|
||||||
LOGGER.trace(String.format("Deleting unconfirmed transaction %s", Base58.encode(transactionData.getSignature())));
|
LOGGER.trace(() -> String.format("Deleting unconfirmed transaction %s", Base58.encode(transactionData.getSignature())));
|
||||||
repository.getTransactionRepository().delete(transactionData);
|
repository.getTransactionRepository().delete(transactionData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,7 +70,7 @@ public class BlockMinter extends Thread {
|
|||||||
|
|
||||||
// Going to need this a lot...
|
// Going to need this a lot...
|
||||||
BlockRepository blockRepository = repository.getBlockRepository();
|
BlockRepository blockRepository = repository.getBlockRepository();
|
||||||
Block previousBlock = null;
|
BlockData previousBlockData = null;
|
||||||
|
|
||||||
List<Block> newBlocks = new ArrayList<>();
|
List<Block> newBlocks = new ArrayList<>();
|
||||||
|
|
||||||
@ -150,8 +151,8 @@ public class BlockMinter extends Thread {
|
|||||||
isMintingPossible = true;
|
isMintingPossible = true;
|
||||||
|
|
||||||
// Check blockchain hasn't changed
|
// Check blockchain hasn't changed
|
||||||
if (previousBlock == null || !Arrays.equals(previousBlock.getSignature(), lastBlockData.getSignature())) {
|
if (previousBlockData == null || !Arrays.equals(previousBlockData.getSignature(), lastBlockData.getSignature())) {
|
||||||
previousBlock = new Block(repository, lastBlockData);
|
previousBlockData = lastBlockData;
|
||||||
newBlocks.clear();
|
newBlocks.clear();
|
||||||
|
|
||||||
// Reduce log timeout
|
// Reduce log timeout
|
||||||
@ -162,12 +163,12 @@ public class BlockMinter extends Thread {
|
|||||||
mintingAccountsData.removeIf(mintingAccountData -> newBlocks.stream().anyMatch(newBlock -> Arrays.equals(newBlock.getBlockData().getMinterPublicKey(), mintingAccountData.getPublicKey())));
|
mintingAccountsData.removeIf(mintingAccountData -> newBlocks.stream().anyMatch(newBlock -> Arrays.equals(newBlock.getBlockData().getMinterPublicKey(), mintingAccountData.getPublicKey())));
|
||||||
|
|
||||||
// Do we need to build any potential new blocks?
|
// Do we need to build any potential new blocks?
|
||||||
List<PrivateKeyAccount> mintingAccounts = mintingAccountsData.stream().map(accountData -> new PrivateKeyAccount(repository, accountData.getPrivateKey())).collect(Collectors.toList());
|
List<PrivateKeyAccount> newBlocksMintingAccounts = mintingAccountsData.stream().map(accountData -> new PrivateKeyAccount(repository, accountData.getPrivateKey())).collect(Collectors.toList());
|
||||||
|
|
||||||
for (PrivateKeyAccount mintingAccount : mintingAccounts) {
|
for (PrivateKeyAccount mintingAccount : newBlocksMintingAccounts) {
|
||||||
// First block does the AT heavy-lifting
|
// First block does the AT heavy-lifting
|
||||||
if (newBlocks.isEmpty()) {
|
if (newBlocks.isEmpty()) {
|
||||||
Block newBlock = Block.mint(repository, previousBlock.getBlockData(), mintingAccount);
|
Block newBlock = Block.mint(repository, previousBlockData, mintingAccount);
|
||||||
if (newBlock == null) {
|
if (newBlock == null) {
|
||||||
// For some reason we can't mint right now
|
// For some reason we can't mint right now
|
||||||
moderatedLog(() -> LOGGER.error("Couldn't build a to-be-minted block"));
|
moderatedLog(() -> LOGGER.error("Couldn't build a to-be-minted block"));
|
||||||
@ -233,8 +234,8 @@ public class BlockMinter extends Thread {
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Pick best block
|
// Pick best block
|
||||||
final int parentHeight = previousBlock.getBlockData().getHeight();
|
final int parentHeight = previousBlockData.getHeight();
|
||||||
final byte[] parentBlockSignature = previousBlock.getSignature();
|
final byte[] parentBlockSignature = previousBlockData.getSignature();
|
||||||
|
|
||||||
BigInteger bestWeight = null;
|
BigInteger bestWeight = null;
|
||||||
|
|
@ -36,7 +36,6 @@ import org.qortal.account.PublicKeyAccount;
|
|||||||
import org.qortal.api.ApiService;
|
import org.qortal.api.ApiService;
|
||||||
import org.qortal.block.Block;
|
import org.qortal.block.Block;
|
||||||
import org.qortal.block.BlockChain;
|
import org.qortal.block.BlockChain;
|
||||||
import org.qortal.block.BlockMinter;
|
|
||||||
import org.qortal.block.BlockChain.BlockTimingByHeight;
|
import org.qortal.block.BlockChain.BlockTimingByHeight;
|
||||||
import org.qortal.controller.Synchronizer.SynchronizationResult;
|
import org.qortal.controller.Synchronizer.SynchronizationResult;
|
||||||
import org.qortal.crypto.Crypto;
|
import org.qortal.crypto.Crypto;
|
||||||
|
@ -7,7 +7,7 @@ import org.qortal.account.Account;
|
|||||||
import org.qortal.account.PrivateKeyAccount;
|
import org.qortal.account.PrivateKeyAccount;
|
||||||
import org.qortal.account.PublicKeyAccount;
|
import org.qortal.account.PublicKeyAccount;
|
||||||
import org.qortal.block.BlockChain;
|
import org.qortal.block.BlockChain;
|
||||||
import org.qortal.block.BlockMinter;
|
import org.qortal.controller.BlockMinter;
|
||||||
import org.qortal.data.account.AccountData;
|
import org.qortal.data.account.AccountData;
|
||||||
import org.qortal.data.transaction.BaseTransactionData;
|
import org.qortal.data.transaction.BaseTransactionData;
|
||||||
import org.qortal.data.transaction.PaymentTransactionData;
|
import org.qortal.data.transaction.PaymentTransactionData;
|
||||||
|
@ -5,7 +5,7 @@ import org.apache.logging.log4j.Logger;
|
|||||||
import org.qortal.account.PrivateKeyAccount;
|
import org.qortal.account.PrivateKeyAccount;
|
||||||
import org.qortal.block.Block;
|
import org.qortal.block.Block;
|
||||||
import org.qortal.block.BlockChain;
|
import org.qortal.block.BlockChain;
|
||||||
import org.qortal.block.BlockMinter;
|
import org.qortal.controller.BlockMinter;
|
||||||
import org.qortal.data.block.BlockData;
|
import org.qortal.data.block.BlockData;
|
||||||
import org.qortal.repository.DataException;
|
import org.qortal.repository.DataException;
|
||||||
import org.qortal.repository.Repository;
|
import org.qortal.repository.Repository;
|
||||||
|
@ -7,7 +7,7 @@ import org.junit.After;
|
|||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.qortal.account.PrivateKeyAccount;
|
import org.qortal.account.PrivateKeyAccount;
|
||||||
import org.qortal.block.BlockMinter;
|
import org.qortal.controller.BlockMinter;
|
||||||
import org.qortal.controller.Controller;
|
import org.qortal.controller.Controller;
|
||||||
import org.qortal.data.account.RewardShareData;
|
import org.qortal.data.account.RewardShareData;
|
||||||
import org.qortal.repository.DataException;
|
import org.qortal.repository.DataException;
|
||||||
|
@ -10,7 +10,7 @@ import org.junit.After;
|
|||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.qortal.account.PrivateKeyAccount;
|
import org.qortal.account.PrivateKeyAccount;
|
||||||
import org.qortal.block.BlockMinter;
|
import org.qortal.controller.BlockMinter;
|
||||||
import org.qortal.controller.Controller;
|
import org.qortal.controller.Controller;
|
||||||
import org.qortal.data.account.RewardShareData;
|
import org.qortal.data.account.RewardShareData;
|
||||||
import org.qortal.data.block.BlockData;
|
import org.qortal.data.block.BlockData;
|
||||||
|
@ -14,8 +14,8 @@ import org.junit.Test;
|
|||||||
import org.qortal.account.PrivateKeyAccount;
|
import org.qortal.account.PrivateKeyAccount;
|
||||||
import org.qortal.asset.Asset;
|
import org.qortal.asset.Asset;
|
||||||
import org.qortal.block.BlockChain;
|
import org.qortal.block.BlockChain;
|
||||||
import org.qortal.block.BlockMinter;
|
|
||||||
import org.qortal.block.BlockChain.RewardByHeight;
|
import org.qortal.block.BlockChain.RewardByHeight;
|
||||||
|
import org.qortal.controller.BlockMinter;
|
||||||
import org.qortal.data.account.AccountBalanceData;
|
import org.qortal.data.account.AccountBalanceData;
|
||||||
import org.qortal.repository.DataException;
|
import org.qortal.repository.DataException;
|
||||||
import org.qortal.repository.Repository;
|
import org.qortal.repository.Repository;
|
||||||
|
Loading…
Reference in New Issue
Block a user