@@ -10,9 +10,11 @@ import com.jd.blockchain.storage.service.ExPolicyKVStorage; | |||||
import com.jd.blockchain.storage.service.VersioningKVStorage; | import com.jd.blockchain.storage.service.VersioningKVStorage; | ||||
import com.jd.blockchain.utils.Bytes; | import com.jd.blockchain.utils.Bytes; | ||||
import com.jd.blockchain.utils.Transactional; | import com.jd.blockchain.utils.Transactional; | ||||
import org.slf4j.Logger; | |||||
import org.slf4j.LoggerFactory; | |||||
public class DataAccountSet implements Transactional, DataAccountQuery { | public class DataAccountSet implements Transactional, DataAccountQuery { | ||||
private Logger logger = LoggerFactory.getLogger(DataAccountSet.class); | |||||
private MerkleAccountSet accountSet; | private MerkleAccountSet accountSet; | ||||
public DataAccountSet(CryptoSetting cryptoSetting, String prefix, ExPolicyKVStorage exStorage, | public DataAccountSet(CryptoSetting cryptoSetting, String prefix, ExPolicyKVStorage exStorage, | ||||
@@ -77,7 +79,7 @@ public class DataAccountSet implements Transactional, DataAccountQuery { | |||||
/** | /** | ||||
* 返回数据账户; <br> | * 返回数据账户; <br> | ||||
* 如果不存在,则返回 null; | * 如果不存在,则返回 null; | ||||
* | |||||
* | |||||
* @param address | * @param address | ||||
* @return | * @return | ||||
*/ | */ | ||||
@@ -110,4 +112,4 @@ public class DataAccountSet implements Transactional, DataAccountQuery { | |||||
public void cancel() { | public void cancel() { | ||||
accountSet.cancel(); | accountSet.cancel(); | ||||
} | } | ||||
} | |||||
} |
@@ -23,9 +23,11 @@ import com.jd.blockchain.storage.service.VersioningKVStorage; | |||||
import com.jd.blockchain.storage.service.utils.BufferedKVStorage; | import com.jd.blockchain.storage.service.utils.BufferedKVStorage; | ||||
import com.jd.blockchain.utils.Bytes; | import com.jd.blockchain.utils.Bytes; | ||||
import com.jd.blockchain.utils.codec.Base58Utils; | import com.jd.blockchain.utils.codec.Base58Utils; | ||||
import org.slf4j.Logger; | |||||
import org.slf4j.LoggerFactory; | |||||
public class LedgerTransactionalEditor implements LedgerEditor { | public class LedgerTransactionalEditor implements LedgerEditor { | ||||
private Logger logger = LoggerFactory.getLogger(LedgerTransactionalEditor.class); | |||||
private static final boolean PARALLEL_DB_WRITE; | private static final boolean PARALLEL_DB_WRITE; | ||||
static { | static { | ||||
@@ -103,7 +105,7 @@ public class LedgerTransactionalEditor implements LedgerEditor { | |||||
/** | /** | ||||
* 创建账本新区块的编辑器; | * 创建账本新区块的编辑器; | ||||
* | |||||
* | |||||
* @param ledgerHash 账本哈希; | * @param ledgerHash 账本哈希; | ||||
* @param ledgerSetting 账本设置; | * @param ledgerSetting 账本设置; | ||||
* @param previousBlock 前置区块; | * @param previousBlock 前置区块; | ||||
@@ -138,7 +140,7 @@ public class LedgerTransactionalEditor implements LedgerEditor { | |||||
/** | /** | ||||
* 创建创世区块的编辑器; | * 创建创世区块的编辑器; | ||||
* | |||||
* | |||||
* @param initSetting | * @param initSetting | ||||
* @param ledgerKeyPrefix | * @param ledgerKeyPrefix | ||||
* @param ledgerExStorage | * @param ledgerExStorage | ||||
@@ -195,7 +197,7 @@ public class LedgerTransactionalEditor implements LedgerEditor { | |||||
/** | /** | ||||
* 检查当前账本是否是指定交易请求的账本; | * 检查当前账本是否是指定交易请求的账本; | ||||
* | |||||
* | |||||
* @param txRequest | * @param txRequest | ||||
* @return | * @return | ||||
*/ | */ | ||||
@@ -301,7 +303,7 @@ public class LedgerTransactionalEditor implements LedgerEditor { | |||||
currentBlock.setTransactionSetHash(previousTxSnapshot.getTransactionSetHash()); | currentBlock.setTransactionSetHash(previousTxSnapshot.getTransactionSetHash()); | ||||
// TODO: 根据所有交易的时间戳的平均值来生成区块的时间戳; | // TODO: 根据所有交易的时间戳的平均值来生成区块的时间戳; | ||||
// long timestamp = | |||||
// long timestamp = | |||||
// currentBlock.setTimestamp(timestamp); | // currentBlock.setTimestamp(timestamp); | ||||
// compute block hash; | // compute block hash; | ||||
@@ -394,7 +396,7 @@ public class LedgerTransactionalEditor implements LedgerEditor { | |||||
/** | /** | ||||
* 用于暂存交易上下文数据的快照对象; | * 用于暂存交易上下文数据的快照对象; | ||||
* | |||||
* | |||||
* @author huanghaiquan | * @author huanghaiquan | ||||
* | * | ||||
*/ | */ | ||||
@@ -404,7 +406,7 @@ public class LedgerTransactionalEditor implements LedgerEditor { | |||||
/** | /** | ||||
* 创世区块的快照对象; | * 创世区块的快照对象; | ||||
* | |||||
* | |||||
* @author huanghaiquan | * @author huanghaiquan | ||||
* | * | ||||
*/ | */ | ||||
@@ -419,7 +421,7 @@ public class LedgerTransactionalEditor implements LedgerEditor { | |||||
/** | /** | ||||
* 交易执行完毕后的快照对象; | * 交易执行完毕后的快照对象; | ||||
* | |||||
* | |||||
* @author huanghaiquan | * @author huanghaiquan | ||||
* | * | ||||
*/ | */ | ||||
@@ -464,12 +466,12 @@ public class LedgerTransactionalEditor implements LedgerEditor { | |||||
/** | /** | ||||
* 交易的上下文; | * 交易的上下文; | ||||
* | |||||
* | |||||
* @author huanghaiquan | * @author huanghaiquan | ||||
* | * | ||||
*/ | */ | ||||
private static class LedgerTransactionContextImpl implements LedgerTransactionContext { | private static class LedgerTransactionContextImpl implements LedgerTransactionContext { | ||||
private Logger logger = LoggerFactory.getLogger(LedgerTransactionContextImpl.class); | |||||
private LedgerTransactionalEditor blockEditor; | private LedgerTransactionalEditor blockEditor; | ||||
private TransactionRequest txRequest; | private TransactionRequest txRequest; | ||||
@@ -522,21 +524,27 @@ public class LedgerTransactionalEditor implements LedgerEditor { | |||||
checkTxState(); | checkTxState(); | ||||
// capture snapshot | // capture snapshot | ||||
logger.debug("before dataset.commit(),[contentHash={}]",this.getTransactionRequest().getTransactionContent().getHash()); | |||||
this.dataset.commit(); | this.dataset.commit(); | ||||
logger.debug("after dataset.commit(),[contentHash={}]",this.getTransactionRequest().getTransactionContent().getHash()); | |||||
TransactionStagedSnapshot txDataSnapshot = takeDataSnapshot(); | TransactionStagedSnapshot txDataSnapshot = takeDataSnapshot(); | ||||
LedgerTransactionData tx; | LedgerTransactionData tx; | ||||
try { | try { | ||||
tx = new LedgerTransactionData(blockEditor.getBlockHeight(), txRequest, txResult, txDataSnapshot, | tx = new LedgerTransactionData(blockEditor.getBlockHeight(), txRequest, txResult, txDataSnapshot, | ||||
operationResultArray(operationResults)); | operationResultArray(operationResults)); | ||||
logger.debug("before txSet.add(),[contentHash={}]",tx.getTransactionContent().getHash()); | |||||
this.txset.add(tx); | this.txset.add(tx); | ||||
logger.debug("after txSet.add(),[contentHash={}]",tx.getTransactionContent().getHash()); | |||||
this.txset.commit(); | this.txset.commit(); | ||||
logger.debug("after txset.commit(),[contentHash={}]",this.getTransactionRequest().getTransactionContent().getHash()); | |||||
} catch (Exception e) { | } catch (Exception e) { | ||||
throw new TransactionRollbackException(e.getMessage(), e); | throw new TransactionRollbackException(e.getMessage(), e); | ||||
} | } | ||||
try { | try { | ||||
this.storage.flush(); | this.storage.flush(); | ||||
logger.debug("after storage.flush(),[contentHash={}]",this.getTransactionRequest().getTransactionContent().getHash()); | |||||
} catch (Exception e) { | } catch (Exception e) { | ||||
throw new BlockRollbackException(e.getMessage(), e); | throw new BlockRollbackException(e.getMessage(), e); | ||||
} | } | ||||
@@ -631,4 +639,4 @@ public class LedgerTransactionalEditor implements LedgerEditor { | |||||
} | } | ||||
} | } | ||||
} | |||||
} |
@@ -13,9 +13,11 @@ import com.jd.blockchain.storage.service.VersioningKVStorage; | |||||
import com.jd.blockchain.utils.Bytes; | import com.jd.blockchain.utils.Bytes; | ||||
import com.jd.blockchain.utils.DataEntry; | import com.jd.blockchain.utils.DataEntry; | ||||
import com.jd.blockchain.utils.Transactional; | import com.jd.blockchain.utils.Transactional; | ||||
import org.slf4j.Logger; | |||||
import org.slf4j.LoggerFactory; | |||||
public class MerkleAccountSet implements Transactional, MerkleProvable, AccountQuery<CompositeAccount> { | public class MerkleAccountSet implements Transactional, MerkleProvable, AccountQuery<CompositeAccount> { | ||||
private Logger logger = LoggerFactory.getLogger(MerkleAccountSet.class); | |||||
static { | static { | ||||
DataContractRegistry.register(MerkleSnapshot.class); | DataContractRegistry.register(MerkleSnapshot.class); | ||||
DataContractRegistry.register(BlockchainIdentity.class); | DataContractRegistry.register(BlockchainIdentity.class); | ||||
@@ -31,7 +33,7 @@ public class MerkleAccountSet implements Transactional, MerkleProvable, AccountQ | |||||
/** | /** | ||||
* The cache of latest version accounts, including accounts getting by querying | * The cache of latest version accounts, including accounts getting by querying | ||||
* and by new regiestering ; | * and by new regiestering ; | ||||
* | |||||
* | |||||
*/ | */ | ||||
// TODO:未考虑大数据量时,由于缺少过期策略,会导致内存溢出的问题; | // TODO:未考虑大数据量时,由于缺少过期策略,会导致内存溢出的问题; | ||||
private Map<Bytes, InnerMerkleAccount> latestAccountsCache = new HashMap<>(); | private Map<Bytes, InnerMerkleAccount> latestAccountsCache = new HashMap<>(); | ||||
@@ -97,7 +99,7 @@ public class MerkleAccountSet implements Transactional, MerkleProvable, AccountQ | |||||
/** | /** | ||||
* 返回账户的总数量; | * 返回账户的总数量; | ||||
* | |||||
* | |||||
* @return | * @return | ||||
*/ | */ | ||||
public long getTotal() { | public long getTotal() { | ||||
@@ -111,7 +113,7 @@ public class MerkleAccountSet implements Transactional, MerkleProvable, AccountQ | |||||
/** | /** | ||||
* 返回最新版本的 Account; | * 返回最新版本的 Account; | ||||
* | |||||
* | |||||
* @param address | * @param address | ||||
* @return | * @return | ||||
*/ | */ | ||||
@@ -122,10 +124,10 @@ public class MerkleAccountSet implements Transactional, MerkleProvable, AccountQ | |||||
/** | /** | ||||
* 账户是否存在;<br> | * 账户是否存在;<br> | ||||
* | |||||
* | |||||
* 如果指定的账户已经注册(通过 {@link #register(String, PubKey)} 方法),但尚未提交(通过 | * 如果指定的账户已经注册(通过 {@link #register(String, PubKey)} 方法),但尚未提交(通过 | ||||
* {@link #commit()} 方法),此方法对该账户仍然返回 false; | * {@link #commit()} 方法),此方法对该账户仍然返回 false; | ||||
* | |||||
* | |||||
* @param address | * @param address | ||||
* @return | * @return | ||||
*/ | */ | ||||
@@ -145,7 +147,7 @@ public class MerkleAccountSet implements Transactional, MerkleProvable, AccountQ | |||||
* 如果账户不存在,则返回 -1;<br> | * 如果账户不存在,则返回 -1;<br> | ||||
* 如果账户已经注册(通过 {@link #register(String, PubKey)} 方法),但尚未提交(通过 {@link #commit()} | * 如果账户已经注册(通过 {@link #register(String, PubKey)} 方法),但尚未提交(通过 {@link #commit()} | ||||
* 方法),则返回 -1; <br> | * 方法),则返回 -1; <br> | ||||
* | |||||
* | |||||
* @param address | * @param address | ||||
* @return | * @return | ||||
*/ | */ | ||||
@@ -161,9 +163,9 @@ public class MerkleAccountSet implements Transactional, MerkleProvable, AccountQ | |||||
/** | /** | ||||
* 返回指定版本的 Account; | * 返回指定版本的 Account; | ||||
* | |||||
* | |||||
* 只有最新版本的账户才能可写的,其它都是只读; | * 只有最新版本的账户才能可写的,其它都是只读; | ||||
* | |||||
* | |||||
* @param address 账户地址; | * @param address 账户地址; | ||||
* @param version 账户版本;如果指定为 -1,则返回最新版本; | * @param version 账户版本;如果指定为 -1,则返回最新版本; | ||||
* @return | * @return | ||||
@@ -200,7 +202,7 @@ public class MerkleAccountSet implements Transactional, MerkleProvable, AccountQ | |||||
// Now, be sure that "acc == null", so get account from storage; | // Now, be sure that "acc == null", so get account from storage; | ||||
// Set readonly for the old version account; | // Set readonly for the old version account; | ||||
boolean readonly = (version > -1 && version < latestVersion) || isReadonly(); | boolean readonly = (version > -1 && version < latestVersion) || isReadonly(); | ||||
long qVersion = version == -1 ? latestVersion : version; | long qVersion = version == -1 ? latestVersion : version; | ||||
// load account from storage; | // load account from storage; | ||||
acc = loadAccount(address, readonly, qVersion); | acc = loadAccount(address, readonly, qVersion); | ||||
@@ -221,11 +223,11 @@ public class MerkleAccountSet implements Transactional, MerkleProvable, AccountQ | |||||
/** | /** | ||||
* 注册一个新账户; <br> | * 注册一个新账户; <br> | ||||
* | |||||
* | |||||
* 如果账户已经存在,则会引发 {@link LedgerException} 异常; <br> | * 如果账户已经存在,则会引发 {@link LedgerException} 异常; <br> | ||||
* | |||||
* | |||||
* 如果指定的地址和公钥不匹配,则会引发 {@link LedgerException} 异常; | * 如果指定的地址和公钥不匹配,则会引发 {@link LedgerException} 异常; | ||||
* | |||||
* | |||||
* @param address 区块链地址; | * @param address 区块链地址; | ||||
* @param pubKey 公钥; | * @param pubKey 公钥; | ||||
* @return 注册成功的账户对象; | * @return 注册成功的账户对象; | ||||
@@ -248,7 +250,11 @@ public class MerkleAccountSet implements Transactional, MerkleProvable, AccountQ | |||||
// 相同的账户已经存在; | // 相同的账户已经存在; | ||||
throw new LedgerException("The registering account already exist!"); | throw new LedgerException("The registering account already exist!"); | ||||
} | } | ||||
logger.debug("before merkleDataset.getVersion...[address={}]",address); | |||||
long version = merkleDataset.getVersion(address); | long version = merkleDataset.getVersion(address); | ||||
logger.debug("after merkleDataset.getVersion...[address={}]",address); | |||||
if (version >= 0) { | if (version >= 0) { | ||||
throw new LedgerException("The registering account already exist!", TransactionState.ACCOUNT_REGISTER_CONFLICT); | throw new LedgerException("The registering account already exist!", TransactionState.ACCOUNT_REGISTER_CONFLICT); | ||||
} | } | ||||
@@ -278,7 +284,7 @@ public class MerkleAccountSet implements Transactional, MerkleProvable, AccountQ | |||||
/** | /** | ||||
* 加载指定版本的账户; | * 加载指定版本的账户; | ||||
* | |||||
* | |||||
* @param address 账户地址; | * @param address 账户地址; | ||||
* @param readonly 是否只读; | * @param readonly 是否只读; | ||||
* @param version 账户的版本;大于等于 0 ; | * @param version 账户的版本;大于等于 0 ; | ||||
@@ -307,7 +313,7 @@ public class MerkleAccountSet implements Transactional, MerkleProvable, AccountQ | |||||
/** | /** | ||||
* 保存账户的根哈希,返回账户的新版本; | * 保存账户的根哈希,返回账户的新版本; | ||||
* | |||||
* | |||||
* @param account | * @param account | ||||
* @return | * @return | ||||
*/ | */ | ||||
@@ -361,7 +367,7 @@ public class MerkleAccountSet implements Transactional, MerkleProvable, AccountQ | |||||
/** | /** | ||||
* 内部实现的账户,监听和同步账户数据的变更; | * 内部实现的账户,监听和同步账户数据的变更; | ||||
* | |||||
* | |||||
* @author huanghaiquan | * @author huanghaiquan | ||||
* | * | ||||
*/ | */ | ||||
@@ -402,4 +408,4 @@ public class MerkleAccountSet implements Transactional, MerkleProvable, AccountQ | |||||
} | } | ||||
} | |||||
} |
@@ -17,17 +17,19 @@ import com.jd.blockchain.utils.DataIterator; | |||||
import com.jd.blockchain.utils.Dataset; | import com.jd.blockchain.utils.Dataset; | ||||
import com.jd.blockchain.utils.Transactional; | import com.jd.blockchain.utils.Transactional; | ||||
import com.jd.blockchain.utils.io.BytesUtils; | import com.jd.blockchain.utils.io.BytesUtils; | ||||
import org.slf4j.Logger; | |||||
import org.slf4j.LoggerFactory; | |||||
/** | /** | ||||
* 对新的数据项按顺序递增进行编号的 Merkle 数据集; <br> | * 对新的数据项按顺序递增进行编号的 Merkle 数据集; <br> | ||||
* | |||||
* | |||||
* 注:此实现不是线程安全的; | * 注:此实现不是线程安全的; | ||||
* | |||||
* | |||||
* @author huanghaiquan | * @author huanghaiquan | ||||
* | * | ||||
*/ | */ | ||||
public class MerkleDataSet implements Transactional, MerkleProvable, Dataset<Bytes, byte[]> { | public class MerkleDataSet implements Transactional, MerkleProvable, Dataset<Bytes, byte[]> { | ||||
private Logger logger = LoggerFactory.getLogger(MerkleDataSet.class); | |||||
/** | /** | ||||
* 4 MB MaxSize of value; | * 4 MB MaxSize of value; | ||||
*/ | */ | ||||
@@ -58,7 +60,7 @@ public class MerkleDataSet implements Transactional, MerkleProvable, Dataset<Byt | |||||
/* | /* | ||||
* (non-Javadoc) | * (non-Javadoc) | ||||
* | |||||
* | |||||
* @see com.jd.blockchain.ledger.core.MerkleProvable#getRootHash() | * @see com.jd.blockchain.ledger.core.MerkleProvable#getRootHash() | ||||
*/ | */ | ||||
@Override | @Override | ||||
@@ -68,7 +70,7 @@ public class MerkleDataSet implements Transactional, MerkleProvable, Dataset<Byt | |||||
/** | /** | ||||
* 创建一个新的 MerkleDataSet; | * 创建一个新的 MerkleDataSet; | ||||
* | |||||
* | |||||
* @param setting 密码设置; | * @param setting 密码设置; | ||||
* @param exPolicyStorage 默克尔树的存储; | * @param exPolicyStorage 默克尔树的存储; | ||||
* @param versioningStorage 数据的存储; | * @param versioningStorage 数据的存储; | ||||
@@ -80,7 +82,7 @@ public class MerkleDataSet implements Transactional, MerkleProvable, Dataset<Byt | |||||
/** | /** | ||||
* 创建一个新的 MerkleDataSet; | * 创建一个新的 MerkleDataSet; | ||||
* | |||||
* | |||||
* @param setting 密码设置; | * @param setting 密码设置; | ||||
* @param exPolicyStorage 默克尔树的存储; | * @param exPolicyStorage 默克尔树的存储; | ||||
* @param versioningStorage 数据的存储; | * @param versioningStorage 数据的存储; | ||||
@@ -111,7 +113,7 @@ public class MerkleDataSet implements Transactional, MerkleProvable, Dataset<Byt | |||||
/** | /** | ||||
* 从指定的 Merkle 根构建的 MerkleDataSet; | * 从指定的 Merkle 根构建的 MerkleDataSet; | ||||
* | |||||
* | |||||
* @param dataStorage | * @param dataStorage | ||||
* @param defaultMerkleHashAlgorithm | * @param defaultMerkleHashAlgorithm | ||||
* @param verifyMerkleHashOnLoad | * @param verifyMerkleHashOnLoad | ||||
@@ -125,7 +127,7 @@ public class MerkleDataSet implements Transactional, MerkleProvable, Dataset<Byt | |||||
/** | /** | ||||
* 从指定的 Merkle 根构建的 MerkleDataSet; | * 从指定的 Merkle 根构建的 MerkleDataSet; | ||||
* | |||||
* | |||||
* @param dataStorage | * @param dataStorage | ||||
* @param defaultMerkleHashAlgorithm | * @param defaultMerkleHashAlgorithm | ||||
* @param verifyMerkleHashOnLoad | * @param verifyMerkleHashOnLoad | ||||
@@ -169,7 +171,7 @@ public class MerkleDataSet implements Transactional, MerkleProvable, Dataset<Byt | |||||
/** | /** | ||||
* 返回理论上允许的最大数据索引; | * 返回理论上允许的最大数据索引; | ||||
* | |||||
* | |||||
* @return | * @return | ||||
*/ | */ | ||||
public long getMaxIndex() { | public long getMaxIndex() { | ||||
@@ -229,7 +231,7 @@ public class MerkleDataSet implements Transactional, MerkleProvable, Dataset<Byt | |||||
/** | /** | ||||
* get the data at the specific index; | * get the data at the specific index; | ||||
* | |||||
* | |||||
* @param fromIndex | * @param fromIndex | ||||
* @return | * @return | ||||
*/ | */ | ||||
@@ -241,7 +243,7 @@ public class MerkleDataSet implements Transactional, MerkleProvable, Dataset<Byt | |||||
/** | /** | ||||
* get the key at the specific index; | * get the key at the specific index; | ||||
* | |||||
* | |||||
* @param fromIndex | * @param fromIndex | ||||
* @return | * @return | ||||
*/ | */ | ||||
@@ -254,14 +256,14 @@ public class MerkleDataSet implements Transactional, MerkleProvable, Dataset<Byt | |||||
// /** | // /** | ||||
// * Create or update the value associated the specified key if the version | // * Create or update the value associated the specified key if the version | ||||
// * checking is passed.<br> | // * checking is passed.<br> | ||||
// * | |||||
// * | |||||
// * The value of the key will be updated only if it's latest version equals the | // * The value of the key will be updated only if it's latest version equals the | ||||
// * specified version argument. <br> | // * specified version argument. <br> | ||||
// * If the key doesn't exist, it will be created when the version arg was -1. | // * If the key doesn't exist, it will be created when the version arg was -1. | ||||
// * <p> | // * <p> | ||||
// * If updating is performed, the version of the key increase by 1. <br> | // * If updating is performed, the version of the key increase by 1. <br> | ||||
// * If creating is performed, the version of the key initialize by 0. <br> | // * If creating is performed, the version of the key initialize by 0. <br> | ||||
// * | |||||
// * | |||||
// * @param key The key of data; | // * @param key The key of data; | ||||
// * @param value The value of data; | // * @param value The value of data; | ||||
// * @param version The expected latest version of the key. | // * @param version The expected latest version of the key. | ||||
@@ -279,14 +281,14 @@ public class MerkleDataSet implements Transactional, MerkleProvable, Dataset<Byt | |||||
/** | /** | ||||
* Create or update the value associated the specified key if the version | * Create or update the value associated the specified key if the version | ||||
* checking is passed.<br> | * checking is passed.<br> | ||||
* | |||||
* | |||||
* The value of the key will be updated only if it's latest version equals the | * The value of the key will be updated only if it's latest version equals the | ||||
* specified version argument. <br> | * specified version argument. <br> | ||||
* If the key doesn't exist, it will be created when the version arg was -1. | * If the key doesn't exist, it will be created when the version arg was -1. | ||||
* <p> | * <p> | ||||
* If updating is performed, the version of the key increase by 1. <br> | * If updating is performed, the version of the key increase by 1. <br> | ||||
* If creating is performed, the version of the key initialize by 0. <br> | * If creating is performed, the version of the key initialize by 0. <br> | ||||
* | |||||
* | |||||
* @param key The key of data; | * @param key The key of data; | ||||
* @param value The value of data; | * @param value The value of data; | ||||
* @param version The expected latest version of the key. | * @param version The expected latest version of the key. | ||||
@@ -342,7 +344,9 @@ public class MerkleDataSet implements Transactional, MerkleProvable, Dataset<Byt | |||||
} | } | ||||
// update merkle tree; | // update merkle tree; | ||||
logger.debug("before merkleTree.setData(...),key={}",key); | |||||
merkleTree.setData(sn, key, newVersion, value); | merkleTree.setData(sn, key, newVersion, value); | ||||
logger.debug("after merkleTree.setData(...),key={}",key); | |||||
// TODO: 未在当前实例的层面,实现对输入键-值的缓冲,而直接写入了存储,而 MerkleTree 在未调用 commit | // TODO: 未在当前实例的层面,实现对输入键-值的缓冲,而直接写入了存储,而 MerkleTree 在未调用 commit | ||||
// 之前是缓冲的,这使得在存储层面的数据会不一致,而未来需要优化; | // 之前是缓冲的,这使得在存储层面的数据会不一致,而未来需要优化; | ||||
@@ -359,7 +363,7 @@ public class MerkleDataSet implements Transactional, MerkleProvable, Dataset<Byt | |||||
/** | /** | ||||
* 返回指定 key 对应的序号,如果不存在,则返回 -1; | * 返回指定 key 对应的序号,如果不存在,则返回 -1; | ||||
* | |||||
* | |||||
* @param key | * @param key | ||||
* @return | * @return | ||||
*/ | */ | ||||
@@ -378,7 +382,7 @@ public class MerkleDataSet implements Transactional, MerkleProvable, Dataset<Byt | |||||
/** | /** | ||||
* 返回默克尔树中记录的指定键的版本,在由默克尔树表示的数据集的快照中,这是指定键的最新版本,<br> | * 返回默克尔树中记录的指定键的版本,在由默克尔树表示的数据集的快照中,这是指定键的最新版本,<br> | ||||
* 但该版本有可能小于实际存储的最新版本(由于后续追加的新修改被之后生成的快照维护); | * 但该版本有可能小于实际存储的最新版本(由于后续追加的新修改被之后生成的快照维护); | ||||
* | |||||
* | |||||
* @param key | * @param key | ||||
* @return 返回指定的键的版本;如果不存在,则返回 -1; | * @return 返回指定的键的版本;如果不存在,则返回 -1; | ||||
*/ | */ | ||||
@@ -396,10 +400,10 @@ public class MerkleDataSet implements Transactional, MerkleProvable, Dataset<Byt | |||||
// /** | // /** | ||||
// * Return the specified version's value;<br> | // * Return the specified version's value;<br> | ||||
// * | |||||
// * | |||||
// * If the key with the specified version doesn't exist, then return null;<br> | // * If the key with the specified version doesn't exist, then return null;<br> | ||||
// * If the version is specified to -1, then return the latest version's value; | // * If the version is specified to -1, then return the latest version's value; | ||||
// * | |||||
// * | |||||
// * @param key | // * @param key | ||||
// * @param version | // * @param version | ||||
// */ | // */ | ||||
@@ -410,10 +414,10 @@ public class MerkleDataSet implements Transactional, MerkleProvable, Dataset<Byt | |||||
/** | /** | ||||
* Return the specified version's value;<br> | * Return the specified version's value;<br> | ||||
* | |||||
* | |||||
* If the key with the specified version doesn't exist, then return null;<br> | * If the key with the specified version doesn't exist, then return null;<br> | ||||
* If the version is specified to -1, then return the latest version's value; | * If the version is specified to -1, then return the latest version's value; | ||||
* | |||||
* | |||||
* @param key | * @param key | ||||
* @param version | * @param version | ||||
*/ | */ | ||||
@@ -432,7 +436,7 @@ public class MerkleDataSet implements Transactional, MerkleProvable, Dataset<Byt | |||||
// /** | // /** | ||||
// * Return the latest version's value; | // * Return the latest version's value; | ||||
// * | |||||
// * | |||||
// * @param key | // * @param key | ||||
// * @return return null if not exist; | // * @return return null if not exist; | ||||
// */ | // */ | ||||
@@ -443,7 +447,7 @@ public class MerkleDataSet implements Transactional, MerkleProvable, Dataset<Byt | |||||
/** | /** | ||||
* Return the latest version's value; | * Return the latest version's value; | ||||
* | |||||
* | |||||
* @param key | * @param key | ||||
* @return return null if not exist; | * @return return null if not exist; | ||||
*/ | */ | ||||
@@ -460,7 +464,7 @@ public class MerkleDataSet implements Transactional, MerkleProvable, Dataset<Byt | |||||
// /** | // /** | ||||
// * Return the latest version entry associated the specified key; If the key | // * Return the latest version entry associated the specified key; If the key | ||||
// * doesn't exist, then return -1; | // * doesn't exist, then return -1; | ||||
// * | |||||
// * | |||||
// * @param key | // * @param key | ||||
// * @return | // * @return | ||||
// */ | // */ | ||||
@@ -472,7 +476,7 @@ public class MerkleDataSet implements Transactional, MerkleProvable, Dataset<Byt | |||||
/** | /** | ||||
* Return the latest version entry associated the specified key; If the key | * Return the latest version entry associated the specified key; If the key | ||||
* doesn't exist, then return -1; | * doesn't exist, then return -1; | ||||
* | |||||
* | |||||
* @param key | * @param key | ||||
* @return | * @return | ||||
*/ | */ | ||||
@@ -487,7 +491,7 @@ public class MerkleDataSet implements Transactional, MerkleProvable, Dataset<Byt | |||||
// } | // } | ||||
/** | /** | ||||
* | |||||
* | |||||
* @param key | * @param key | ||||
* @return Null if the key doesn't exist! | * @return Null if the key doesn't exist! | ||||
*/ | */ | ||||
@@ -565,7 +569,7 @@ public class MerkleDataSet implements Transactional, MerkleProvable, Dataset<Byt | |||||
/* | /* | ||||
* (non-Javadoc) | * (non-Javadoc) | ||||
* | |||||
* | |||||
* @see com.jd.blockchain.ledger.core.MerkleProvable#getProof(java.lang.String) | * @see com.jd.blockchain.ledger.core.MerkleProvable#getProof(java.lang.String) | ||||
*/ | */ | ||||
@Override | @Override | ||||
@@ -579,7 +583,7 @@ public class MerkleDataSet implements Transactional, MerkleProvable, Dataset<Byt | |||||
/** | /** | ||||
* A wrapper for {@link DataEntry} and {@link MerkleProof}; | * A wrapper for {@link DataEntry} and {@link MerkleProof}; | ||||
* | |||||
* | |||||
* @author huanghaiquan | * @author huanghaiquan | ||||
* | * | ||||
*/ | */ | ||||
@@ -737,4 +741,4 @@ public class MerkleDataSet implements Transactional, MerkleProvable, Dataset<Byt | |||||
} | } | ||||
} | |||||
} |
@@ -84,14 +84,14 @@ public class TransactionBatchProcessor implements TransactionBatchProcess { | |||||
public TransactionBatchProcessor(LedgerRepository ledgerRepo, OperationHandleRegisteration handlesRegisteration) { | public TransactionBatchProcessor(LedgerRepository ledgerRepo, OperationHandleRegisteration handlesRegisteration) { | ||||
this.ledger = ledgerRepo; | this.ledger = ledgerRepo; | ||||
this.handlesRegisteration = handlesRegisteration; | this.handlesRegisteration = handlesRegisteration; | ||||
LedgerBlock ledgerBlock = ledgerRepo.getLatestBlock(); | LedgerBlock ledgerBlock = ledgerRepo.getLatestBlock(); | ||||
LedgerDataQuery ledgerDataQuery = ledgerRepo.getLedgerData(ledgerBlock); | LedgerDataQuery ledgerDataQuery = ledgerRepo.getLedgerData(ledgerBlock); | ||||
LedgerAdminDataQuery previousAdminDataset = ledgerDataQuery.getAdminDataset(); | LedgerAdminDataQuery previousAdminDataset = ledgerDataQuery.getAdminDataset(); | ||||
this.securityManager = new LedgerSecurityManagerImpl(previousAdminDataset.getAdminInfo().getRolePrivileges(), | this.securityManager = new LedgerSecurityManagerImpl(previousAdminDataset.getAdminInfo().getRolePrivileges(), | ||||
previousAdminDataset.getAdminInfo().getAuthorizations(), previousAdminDataset.getParticipantDataset(), | previousAdminDataset.getAdminInfo().getAuthorizations(), previousAdminDataset.getParticipantDataset(), | ||||
ledgerDataQuery.getUserAccountSet()); | ledgerDataQuery.getUserAccountSet()); | ||||
this.newBlockEditor = ledgerRepo.createNextBlock(); | this.newBlockEditor = ledgerRepo.createNextBlock(); | ||||
} | } | ||||
@@ -115,7 +115,7 @@ public class TransactionBatchProcessor implements TransactionBatchProcess { | |||||
/* | /* | ||||
* (non-Javadoc) | * (non-Javadoc) | ||||
* | |||||
* | |||||
* @see | * @see | ||||
* com.jd.blockchain.ledger.core.impl.TransactionBatchProcess#schedule(com.jd. | * com.jd.blockchain.ledger.core.impl.TransactionBatchProcess#schedule(com.jd. | ||||
* blockchain.ledger.TransactionRequest) | * blockchain.ledger.TransactionRequest) | ||||
@@ -151,6 +151,8 @@ public class TransactionBatchProcessor implements TransactionBatchProcess { | |||||
LedgerTransactionContext txCtx = newBlockEditor.newTransaction(request); | LedgerTransactionContext txCtx = newBlockEditor.newTransaction(request); | ||||
// 处理交易; | // 处理交易; | ||||
LOGGER.debug("before handleTx...after checkRequest()... --[BlockHeight={}][RequestHash={}][TxHash={}]", | |||||
newBlockEditor.getBlockHeight(), request.getHash(), request.getTransactionContent().getHash()); | |||||
resp = handleTx(reqExt, txCtx); | resp = handleTx(reqExt, txCtx); | ||||
LOGGER.debug("Complete handling transaction. --[BlockHeight={}][RequestHash={}][TxHash={}]", | LOGGER.debug("Complete handling transaction. --[BlockHeight={}][RequestHash={}][TxHash={}]", | ||||
@@ -262,9 +264,9 @@ public class TransactionBatchProcessor implements TransactionBatchProcess { | |||||
/** | /** | ||||
* 处理交易;<br> | * 处理交易;<br> | ||||
* | |||||
* | |||||
* 此方法会处理所有的异常,以不同结果的 {@link TransactionResponse} 返回; | * 此方法会处理所有的异常,以不同结果的 {@link TransactionResponse} 返回; | ||||
* | |||||
* | |||||
* @param request | * @param request | ||||
* @param txCtx | * @param txCtx | ||||
* @return | * @return | ||||
@@ -299,7 +301,11 @@ public class TransactionBatchProcessor implements TransactionBatchProcess { | |||||
// 提交交易(事务); | // 提交交易(事务); | ||||
result = TransactionState.SUCCESS; | result = TransactionState.SUCCESS; | ||||
LOGGER.debug("before commit(). --[BlockHeight={}][RequestHash={}][TxHash={}]", | |||||
newBlockEditor.getBlockHeight(), request.getHash(), request.getTransactionContent().getHash()); | |||||
txCtx.commit(result, operationResults); | txCtx.commit(result, operationResults); | ||||
LOGGER.debug("after commit(). --[BlockHeight={}][RequestHash={}][TxHash={}]", | |||||
newBlockEditor.getBlockHeight(), request.getHash(), request.getTransactionContent().getHash()); | |||||
} catch (TransactionRollbackException e) { | } catch (TransactionRollbackException e) { | ||||
result = TransactionState.IGNORED_BY_TX_FULL_ROLLBACK; | result = TransactionState.IGNORED_BY_TX_FULL_ROLLBACK; | ||||
txCtx.rollback(); | txCtx.rollback(); | ||||
@@ -372,7 +378,7 @@ public class TransactionBatchProcessor implements TransactionBatchProcess { | |||||
/** | /** | ||||
* 直接丢弃交易; | * 直接丢弃交易; | ||||
* | |||||
* | |||||
* @param request | * @param request | ||||
* @param txState | * @param txState | ||||
* @return 丢弃交易的回复;只包含原始请求中的交易内容哈希和交易被丢弃的原因,而不包含区块信息; | * @return 丢弃交易的回复;只包含原始请求中的交易内容哈希和交易被丢弃的原因,而不包含区块信息; | ||||
@@ -390,7 +396,7 @@ public class TransactionBatchProcessor implements TransactionBatchProcess { | |||||
/* | /* | ||||
* (non-Javadoc) | * (non-Javadoc) | ||||
* | |||||
* | |||||
* @see com.jd.blockchain.ledger.core.impl.TransactionBatchProcess#prepare() | * @see com.jd.blockchain.ledger.core.impl.TransactionBatchProcess#prepare() | ||||
*/ | */ | ||||
@Override | @Override | ||||
@@ -405,7 +411,7 @@ public class TransactionBatchProcessor implements TransactionBatchProcess { | |||||
/* | /* | ||||
* (non-Javadoc) | * (non-Javadoc) | ||||
* | |||||
* | |||||
* @see | * @see | ||||
* com.jd.blockchain.ledger.core.impl.TransactionBatchProcess#cancel(com.jd. | * com.jd.blockchain.ledger.core.impl.TransactionBatchProcess#cancel(com.jd. | ||||
* blockchain.ledger.ExecutionState) | * blockchain.ledger.ExecutionState) | ||||
@@ -12,9 +12,11 @@ import com.jd.blockchain.storage.service.ExPolicyKVStorage; | |||||
import com.jd.blockchain.storage.service.VersioningKVStorage; | import com.jd.blockchain.storage.service.VersioningKVStorage; | ||||
import com.jd.blockchain.utils.Bytes; | import com.jd.blockchain.utils.Bytes; | ||||
import com.jd.blockchain.utils.Transactional; | import com.jd.blockchain.utils.Transactional; | ||||
import org.slf4j.Logger; | |||||
import org.slf4j.LoggerFactory; | |||||
public class TransactionSet implements Transactional, TransactionQuery { | public class TransactionSet implements Transactional, TransactionQuery { | ||||
private Logger logger = LoggerFactory.getLogger(TransactionSet.class); | |||||
static { | static { | ||||
DataContractRegistry.register(LedgerTransaction.class); | DataContractRegistry.register(LedgerTransaction.class); | ||||
} | } | ||||
@@ -67,7 +69,7 @@ public class TransactionSet implements Transactional, TransactionQuery { | |||||
/** | /** | ||||
* Create a new TransactionSet which can be added transaction; | * Create a new TransactionSet which can be added transaction; | ||||
* | |||||
* | |||||
* @param setting | * @param setting | ||||
* @param merkleTreeStorage | * @param merkleTreeStorage | ||||
* @param dataStorage | * @param dataStorage | ||||
@@ -80,7 +82,7 @@ public class TransactionSet implements Transactional, TransactionQuery { | |||||
/** | /** | ||||
* Create TransactionSet which is readonly to the history transactions; | * Create TransactionSet which is readonly to the history transactions; | ||||
* | |||||
* | |||||
* @param setting | * @param setting | ||||
* @param merkleTreeStorage | * @param merkleTreeStorage | ||||
* @param dataStorage | * @param dataStorage | ||||
@@ -12,16 +12,18 @@ import com.jd.blockchain.ledger.core.OperationHandleContext; | |||||
import com.jd.blockchain.ledger.core.SecurityContext; | import com.jd.blockchain.ledger.core.SecurityContext; | ||||
import com.jd.blockchain.ledger.core.SecurityPolicy; | import com.jd.blockchain.ledger.core.SecurityPolicy; | ||||
import com.jd.blockchain.ledger.core.TransactionRequestExtension; | import com.jd.blockchain.ledger.core.TransactionRequestExtension; | ||||
import org.slf4j.Logger; | |||||
import org.slf4j.LoggerFactory; | |||||
/** | /** | ||||
* 执行直接账本操作的处理类; | * 执行直接账本操作的处理类; | ||||
* | |||||
* | |||||
* @author huanghaiquan | * @author huanghaiquan | ||||
* | * | ||||
* @param <T> | * @param <T> | ||||
*/ | */ | ||||
public abstract class AbstractLedgerOperationHandle<T extends Operation> implements OperationHandle { | public abstract class AbstractLedgerOperationHandle<T extends Operation> implements OperationHandle { | ||||
private Logger logger = LoggerFactory.getLogger(this.getClass()); | |||||
static { | static { | ||||
DataContractRegistry.register(BytesValue.class); | DataContractRegistry.register(BytesValue.class); | ||||
} | } | ||||
@@ -52,8 +54,11 @@ public abstract class AbstractLedgerOperationHandle<T extends Operation> impleme | |||||
// 操作账本; | // 操作账本; | ||||
@SuppressWarnings("unchecked") | @SuppressWarnings("unchecked") | ||||
T concretedOp = (T) op; | T concretedOp = (T) op; | ||||
logger.debug("before doProcess()... --[RequestHash={}][TxHash={}]", | |||||
requestContext.getHash(), requestContext.getTransactionContent().getHash()); | |||||
doProcess(concretedOp, newBlockDataset, requestContext, ledger, handleContext); | doProcess(concretedOp, newBlockDataset, requestContext, ledger, handleContext); | ||||
logger.debug("after doProcess()... --[RequestHash={}][TxHash={}]", | |||||
requestContext.getHash(), requestContext.getTransactionContent().getHash()); | |||||
// 账本操作没有返回值; | // 账本操作没有返回值; | ||||
return null; | return null; | ||||
} | } | ||||
@@ -10,9 +10,11 @@ import com.jd.blockchain.ledger.core.OperationHandleContext; | |||||
import com.jd.blockchain.ledger.core.SecurityContext; | import com.jd.blockchain.ledger.core.SecurityContext; | ||||
import com.jd.blockchain.ledger.core.SecurityPolicy; | import com.jd.blockchain.ledger.core.SecurityPolicy; | ||||
import com.jd.blockchain.ledger.core.TransactionRequestExtension; | import com.jd.blockchain.ledger.core.TransactionRequestExtension; | ||||
import org.slf4j.Logger; | |||||
import org.slf4j.LoggerFactory; | |||||
public class DataAccountRegisterOperationHandle extends AbstractLedgerOperationHandle<DataAccountRegisterOperation> { | public class DataAccountRegisterOperationHandle extends AbstractLedgerOperationHandle<DataAccountRegisterOperation> { | ||||
private Logger logger = LoggerFactory.getLogger(this.getClass()); | |||||
public DataAccountRegisterOperationHandle() { | public DataAccountRegisterOperationHandle() { | ||||
super(DataAccountRegisterOperation.class); | super(DataAccountRegisterOperation.class); | ||||
} | } | ||||
@@ -29,7 +31,9 @@ public class DataAccountRegisterOperationHandle extends AbstractLedgerOperationH | |||||
// 操作账本; | // 操作账本; | ||||
DataAccountRegisterOperation dataAccountRegOp = (DataAccountRegisterOperation) op; | DataAccountRegisterOperation dataAccountRegOp = (DataAccountRegisterOperation) op; | ||||
BlockchainIdentity bid = dataAccountRegOp.getAccountID(); | BlockchainIdentity bid = dataAccountRegOp.getAccountID(); | ||||
logger.debug("before register.[dataAddress={}]",bid.getAddress()); | |||||
newBlockDataset.getDataAccountSet().register(bid.getAddress(), bid.getPubKey(), null); | newBlockDataset.getDataAccountSet().register(bid.getAddress(), bid.getPubKey(), null); | ||||
logger.debug("after register.[dataAddress={}]",bid.getAddress()); | |||||
} | } | ||||
} | } |
@@ -41,6 +41,7 @@ public class RolesConfigureOperationHandle extends AbstractLedgerOperationHandle | |||||
rp.disable(rpcfg.getDisableLedgerPermissions()); | rp.disable(rpcfg.getDisableLedgerPermissions()); | ||||
rp.disable(rpcfg.getDisableTransactionPermissions()); | rp.disable(rpcfg.getDisableTransactionPermissions()); | ||||
rpSettings.updateRolePrivilege(rp); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
@@ -14,6 +14,8 @@ import com.jd.blockchain.service.TransactionEngine; | |||||
import com.jd.blockchain.utils.codec.Base58Utils; | import com.jd.blockchain.utils.codec.Base58Utils; | ||||
import com.jd.blockchain.utils.concurrent.AsyncFuture; | import com.jd.blockchain.utils.concurrent.AsyncFuture; | ||||
import com.jd.blockchain.utils.concurrent.CompletableAsyncFuture; | import com.jd.blockchain.utils.concurrent.CompletableAsyncFuture; | ||||
import org.slf4j.Logger; | |||||
import org.slf4j.LoggerFactory; | |||||
import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
import org.springframework.stereotype.Component; | import org.springframework.stereotype.Component; | ||||
@@ -37,7 +39,7 @@ import java.util.concurrent.locks.ReentrantLock; | |||||
*/ | */ | ||||
@Component | @Component | ||||
public class ConsensusMessageDispatcher implements MessageHandle { | public class ConsensusMessageDispatcher implements MessageHandle { | ||||
private Logger logger = LoggerFactory.getLogger(this.getClass()); | |||||
@Autowired | @Autowired | ||||
private TransactionEngine txEngine; | private TransactionEngine txEngine; | ||||
@@ -119,7 +121,9 @@ public class ConsensusMessageDispatcher implements MessageHandle { | |||||
if (!realmProcessor.getCurrBatchId().equalsIgnoreCase(batchId)) { | if (!realmProcessor.getCurrBatchId().equalsIgnoreCase(batchId)) { | ||||
throw new IllegalArgumentException("BatchId is not begin!"); | throw new IllegalArgumentException("BatchId is not begin!"); | ||||
} | } | ||||
logger.debug("before realmProcessor.commit(),[batchId={}]",batchId); | |||||
realmProcessor.commit(); | realmProcessor.commit(); | ||||
logger.debug("after realmProcessor.commit(),[batchId={}]",batchId); | |||||
// realmProcessorMap.remove(realmName); | // realmProcessorMap.remove(realmName); | ||||
} | } | ||||