Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/crypto/Schnorr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ SchnorrKeyPair* Schnorr::generateKey(BigInteger seed) {
}

SchnorrKeyPair* Schnorr::generateKey(){
BigInteger s = BigInteger::ramdom();
BigInteger s = BigInteger::random();

return generateKey(s);
}
Expand All @@ -59,7 +59,7 @@ SchnorrSignature* codablecash::Schnorr::sign(const BigInteger& s, const BigInteg
}

SchnorrSignature* Schnorr::sign(const BigInteger& s, const BigInteger& p, const uint8_t* data, size_t size){
BigInteger r = BigInteger::ramdom().modSelf(cnsts.Q_1);
BigInteger r = BigInteger::random().modSelf(cnsts.Q_1);
BigInteger powG = cnsts.G.modPow(r, cnsts.Q);

BigInteger* e = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion src/ecda/ScPrivateKey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ ScPrivateKey::ScPrivateKey(const BigInteger* seed, uint64_t solt) : keyvalue((in
}

ScPrivateKey::ScPrivateKey() : keyvalue((int64_t)0) {
this->keyvalue = BigInteger::ramdom().mod(ScPrivateKey::p);
this->keyvalue = BigInteger::random().mod(ScPrivateKey::p);
}

ScPrivateKey::~ScPrivateKey() {
Expand Down
2 changes: 1 addition & 1 deletion src/ecda/ScSignature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ ScSignature::~ScSignature() {
void ScSignature::sign(ByteBuffer* data, const BigInteger s) {
Secp256k1Point G;

BigInteger r = BigInteger::ramdom().mod(Secp256k1Point::p);
BigInteger r = BigInteger::random().mod(Secp256k1Point::p);

Secp256k1Point rG = G.multiple(r);

Expand Down
2 changes: 1 addition & 1 deletion src/musig/SimpleMuSigSigner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Secp256k1Point SimpleMuSigSigner::getxG() {
}

Secp256k1Point SimpleMuSigSigner::getrG() {
this->r = BigInteger::ramdom(BigInteger(0L), Secp256k1Point::n);
this->r = BigInteger::random(BigInteger(0L), Secp256k1Point::n);
Secp256k1Point G;

return G.multiple(this->r);
Expand Down
1 change: 1 addition & 0 deletions src_blockchain/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ add_subdirectory(bc_status_cache)
add_subdirectory(bc_status_cache_context)
add_subdirectory(bc_status_cache_context_finalizer)
add_subdirectory(bc_status_cache_data)
add_subdirectory(bc_status_cache_extend_shard)
add_subdirectory(bc_status_cache_lockin)
add_subdirectory(bc_status_cache_vote)
add_subdirectory(bc_trx)
Expand Down
16 changes: 10 additions & 6 deletions src_blockchain/bc/CodablecashNodeInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ void CodablecashNodeInstance::startNetwork(const UnicodeString *host, int port)
this->p2pServer = new P2pServer(this->logger, this);
this->p2pManager = new BlochchainP2pManager();

this->p2pManager->init(this->blockchain->getNumZones());
this->p2pManager->init(this->statusCache->getNumZones());

this->p2pServer->addConnectionListener(this->p2pManager);

Expand Down Expand Up @@ -233,7 +233,7 @@ void CodablecashNodeInstance::shutdownNetwork() {
}

void CodablecashNodeInstance::startBlockGenerator(const MiningConfig *config) {
uint16_t zone = this->blockchain->getZoneSelf();
uint16_t zone = this->statusCache->getZoneSelf();

this->powManager = new PoWManager(this->logger, config);
this->blockGenerator = this->allocator->newBlockGenerator(zone, this->param, this->memoryPool, this->ctrl, config, this->logger);
Expand Down Expand Up @@ -378,7 +378,7 @@ void CodablecashNodeInstance::loginNode(uint16_t zone, P2pHandshake *handshake,
// login
NodeIdentifierSource* source = this->p2pRequestProcessor->getNetworkKey();

uint16_t zoneSelf = this->blockchain->getZoneSelf();
uint16_t zoneSelf = this->statusCache->getZoneSelf();
LoginPubSubCommand cmd(zoneSelf, canonicalName);

{
Expand Down Expand Up @@ -414,11 +414,11 @@ NodeIdentifierSource* CodablecashNodeInstance::getNetworkKey() const noexcept {
}

uint16_t CodablecashNodeInstance::getZoneSelf() const noexcept {
return this->blockchain->getZoneSelf();
return this->statusCache->getZoneSelf();
}

int CodablecashNodeInstance::getNumZones() const noexcept {
return this->blockchain->getNumZones();
return this->statusCache->getNumZones();
}

void CodablecashNodeInstance::maintainNetwork() {
Expand Down Expand Up @@ -495,7 +495,7 @@ void CodablecashNodeInstance::setNodeName(const UnicodeString *name) noexcept {
}

void CodablecashNodeInstance::validateZone(uint16_t zone) const {
uint16_t numZone = this->blockchain->getNumZones();
uint16_t numZone = this->statusCache->getNumZones();

ExceptionThrower<InvalidZoneException>::throwExceptionIfCondition(numZone <= zone, L"", __FILE__, __LINE__);
}
Expand All @@ -515,4 +515,8 @@ int CodablecashNodeInstance::getListningPort() const noexcept {
return this->p2pServer->getListningPort();
}

void CodablecashNodeInstance::setShardExtendValidator(const AbstractShardExtentionValidator *validator) {
this->statusCache->setShardExtentionValidator(validator);
}

} /* namespace codablecash */
4 changes: 4 additions & 0 deletions src_blockchain/bc/CodablecashNodeInstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class P2pDnsManager;
class P2pHandshake;
class P2pNodeRecord;
class NodeIdentifier;
class AbstractShardExtentionValidator;


class CodablecashNodeInstance : public IPubsubCommandExecutor {
public:
Expand Down Expand Up @@ -132,6 +134,8 @@ class CodablecashNodeInstance : public IPubsubCommandExecutor {
return this->blockGenerator;
}

void setShardExtendValidator(const AbstractShardExtentionValidator *validator);

private:
void __init(const File* baseDir, ISystemLogger* logger, const CodablecashSystemParam* config);
void __maintainNetwork(uint16_t zone);
Expand Down
6 changes: 6 additions & 0 deletions src_blockchain/bc/CodablecashSystemParam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ CodablecashSystemParam::CodablecashSystemParam(const CodablecashSystemParam &ins
this->consensusTrxAllowedDelayMillis = inst.consensusTrxAllowedDelayMillis;

this->consensusPosVoteLimitMillis = inst.consensusPosVoteLimitMillis;

this->remoteUtxoSaveHeightPeriod = inst.remoteUtxoSaveHeightPeriod;
this->remoteUtxoExpireHeight = inst.remoteUtxoExpireHeight;
}

CodablecashSystemParam::CodablecashSystemParam() {
Expand Down Expand Up @@ -85,6 +88,9 @@ CodablecashSystemParam::CodablecashSystemParam() {
this->consensusTrxAllowedDelayMillis = 3000;

this->consensusPosVoteLimitMillis = 20000;

this->remoteUtxoSaveHeightPeriod = 10000;
this->remoteUtxoExpireHeight = 5000;
}

CodablecashSystemParam::~CodablecashSystemParam() {
Expand Down
14 changes: 14 additions & 0 deletions src_blockchain/bc/CodablecashSystemParam.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

namespace codablecash {

class BlockchainSoftwareVersion;


class CodablecashSystemParam {
public:
CodablecashSystemParam(const CodablecashSystemParam& inst);
Expand Down Expand Up @@ -112,6 +115,13 @@ class CodablecashSystemParam {
return this->consensusPosVoteLimitMillis;
}

uint64_t getRemoteUtxoSaveHeightPeriod(const BlockchainSoftwareVersion* version) const noexcept {
return this->remoteUtxoSaveHeightPeriod;
}
uint64_t getRemoteUtxoExpireHeight(const BlockchainSoftwareVersion* version) const noexcept {
return this->remoteUtxoExpireHeight;
}

private:
// pow
uint16_t powHashrateBlocks;
Expand Down Expand Up @@ -160,6 +170,10 @@ class CodablecashSystemParam {
// Pos Vote Limit
uint32_t consensusPosVoteLimitMillis;

// Remote UtxoId to Store period by height
uint64_t remoteUtxoSaveHeightPeriod;
uint64_t remoteUtxoExpireHeight;

};

} /* namespace codablecash */
Expand Down
2 changes: 1 addition & 1 deletion src_blockchain/bc_base/Abstract32BytesId.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ ByteBuffer* Abstract32BytesId::makeRandom16Bytes() {
int size = 0;
BigInteger p(L"0", 16);
do{
BigInteger seed = BigInteger::ramdom();
BigInteger seed = BigInteger::random();

BigInteger s = seed.mod(Abstract32BytesId::Q);
p = G.modPow(s, Abstract32BytesId::Q);
Expand Down
7 changes: 2 additions & 5 deletions src_blockchain/bc_base_trx_index/TransactionDataFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,8 @@ IBlockObject* TransactionDataFactory::makeDataFromBinary(ByteBuffer *in) {
return TransactionData::fromBinary(in);
}

void TransactionDataFactory::registerData(const AbstractBtreeKey *key,
const IBlockObject *data, DataNode *dataNode,
BtreeStorage *store) const {
uint64_t dataFpos = store->storeData(data);
dataNode->setDataFpos(dataFpos);
void TransactionDataFactory::registerData(const AbstractBtreeKey *key, const IBlockObject *data, DataNode *dataNode, BtreeStorage *store) const {
AbstractBtreeDataFactory::registerData(key, data, dataNode, store);
}

bool TransactionDataFactory::beforeRemove(DataNode *dataNode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ IBlockObject* TransactionIdDataFactory::makeDataFromBinary(ByteBuffer *in) {

void TransactionIdDataFactory::registerData(const AbstractBtreeKey *key,
const IBlockObject *data, DataNode *dataNode, BtreeStorage *store) const {
uint64_t dataFpos = store->storeData(data);
dataNode->setDataFpos(dataFpos);
AbstractBtreeDataFactory::registerData(key, data, dataNode, store);
}

bool TransactionIdDataFactory::beforeRemove(DataNode *dataNode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@ IBlockObject* AddressDescriptorDataFactory::makeDataFromBinary(ByteBuffer *in) {
}

void AddressDescriptorDataFactory::registerData(const AbstractBtreeKey *key,
const IBlockObject *data, DataNode *dataNode,
BtreeStorage *store) const {
uint64_t dataFpos = store->storeData(data);
dataNode->setDataFpos(dataFpos);
const IBlockObject *data, DataNode *dataNode, BtreeStorage *store) const {
AbstractBtreeDataFactory::registerData(key, data, dataNode, store);
}

bool AddressDescriptorDataFactory::beforeRemove(DataNode *dataNode,
Expand Down
3 changes: 1 addition & 2 deletions src_blockchain/bc_base_utxo_index/UtxoDataFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ IBlockObject* UtxoDataFactory::makeDataFromBinary(ByteBuffer *in) {

void UtxoDataFactory::registerData(const AbstractBtreeKey *key,
const IBlockObject *data, DataNode *dataNode, BtreeStorage *store) const {
uint64_t dataFpos = store->storeData(data);
dataNode->setDataFpos(dataFpos);
AbstractBtreeDataFactory::registerData(key, data, dataNode, store);
}

bool UtxoDataFactory::beforeRemove(DataNode *dataNode, BtreeStorage *store, const AbstractBtreeKey *key) const {
Expand Down
1 change: 1 addition & 0 deletions src_blockchain/bc_block/Block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ void Block::addControlTransaction(const AbstractControlTransaction *trx) noexcep
case AbstractBlockchainTransaction::TRX_TYPE_VOTE_BLOCK:
addVote(dynamic_cast<const VoteBlockTransaction*>(trx));
break;
// FIXME[multishard]add header command to register new zone
default:
this->body->addControlTransaction(trx);
break;
Expand Down
4 changes: 4 additions & 0 deletions src_blockchain/bc_block/BlockHeader.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ class BlockHeader : public alinous::IBlockObject {
void addHeaderCommand(const AbstractBlockHeaderCommand* cmd);
bool hasHeaderCommnads() const noexcept;

ArrayList<AbstractBlockHeaderCommand>* getHeaderCommands() const noexcept {
return this->commnads;
}

private:
BlockVersion* version;

Expand Down
5 changes: 5 additions & 0 deletions src_blockchain/bc_block_generator/BlockGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,11 @@ void BlockGenerator::importInterChainCommunicationTransactions2Block(MemPoolTran
if(result == TrxValidationResult::OK){
block->addInterChainCommunicationTransaction(trx);
context->importInterChainCommunicationTransaction(header, trx, this->logger);

uint8_t tyxType = trx->getType();
if(tyxType == AbstractInterChainCommunicationTansaction::TRX_TYPE_ICC_ZONE_EXTEND_REQUESTED){
// FIXME[multishard] add RecognizedNewShardCommand to the header
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@

#include "bc_block_header_command/AbstractBlockHeaderCommand.h"
#include "bc_block_header_command/NewShardZoneCommand.h"
#include "bc_block_header_command/RecognizedNewShardCommand.h"

#include "base_io/ByteBuffer.h"

#include "base/StackRelease.h"


namespace codablecash {

AbstractBlockHeaderCommand::AbstractBlockHeaderCommand(const AbstractBlockHeaderCommand &inst) {
Expand All @@ -35,6 +37,9 @@ AbstractBlockHeaderCommand* AbstractBlockHeaderCommand::createFromBinary(ByteBuf
case NEW_SHARD_COMMAND:
ret = new NewShardZoneCommand();
break;
case RECOGNIZED_SHARD_COMMAND:
ret = new RecognizedNewShardCommand();
break;
default:
return nullptr;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,16 @@ using namespace alinous;

namespace codablecash {

class BlockHeader;
class BlockchainStatusCache;
class CodablecashBlockchain;
class CodablecashSystemParam;
class ILockinManager;

class AbstractBlockHeaderCommand : public alinous::IBlockObject {
public:
static constexpr const uint16_t NEW_SHARD_COMMAND = 1;
static constexpr const uint16_t RECOGNIZED_SHARD_COMMAND = 2;

AbstractBlockHeaderCommand(const AbstractBlockHeaderCommand& inst);
explicit AbstractBlockHeaderCommand(uint16_t type);
Expand All @@ -30,6 +37,9 @@ class AbstractBlockHeaderCommand : public alinous::IBlockObject {

virtual void fromBinary(ByteBuffer* in) = 0;

virtual void onFinalize(const BlockHeader *header, BlockchainStatusCache* statusCache, CodablecashBlockchain* blockchain, ILockinManager *lockinManager, const CodablecashSystemParam* config) = 0;


protected:
uint16_t type;
};
Expand Down
1 change: 1 addition & 0 deletions src_blockchain/bc_block_header_command/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
set(__src
AbstractBlockHeaderCommand.cpp
NewShardZoneCommand.cpp
RecognizedNewShardCommand.cpp
)
handle_sub(codablecashlib "${__src}" blockchain bc_block_header_command)
Loading