Skip to content

Commit

Permalink
wip confidential assetchains CAC, assets CA impl
Browse files Browse the repository at this point in the history
CAC init, main params, cons. rules. CA creation, sending & burn
  • Loading branch information
freenetcoder committed Nov 12, 2019
1 parent d881d9f commit 4d2c7ea
Show file tree
Hide file tree
Showing 29 changed files with 1,156 additions and 129 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ set(VERSION_REVISION 0)
set(GIT_COMMIT_HASH "unknown")

# uncoment next line for testnet
set(GRIMM_TESTNET TRUE)
# set(GRIMM_TESTNET TRUE)

if(GRIMM_TESTNET)
add_definitions(-DGRIMM_TESTNET)
Expand Down
12 changes: 10 additions & 2 deletions core/block_crypt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,10 @@ namespace grimm
ptExcNested += pt;

if (!m_Signature.IsValid(hv, ptExcNested))
return false;
{
std::cout << "--- Invalid Сommitment " << m_Commitment << "\n";
return false;
}

*pExcess += pt;

Expand Down Expand Up @@ -488,7 +491,7 @@ namespace grimm
val = -m_AssetEmission;
sc.m_hGen = -sc.m_hGen;
}

std::cout << "--- Asset emission: " << val << "\n";
ECC::Tag::AddValue(*pExcess, &sc.m_hGen, val);
}
}
Expand Down Expand Up @@ -930,6 +933,11 @@ namespace grimm
// at Emission.Drop1 - 5/8
// each Emission.Drop1 cycle - 1/2

if (h == 0)
{
hEnd = Rules::HeightGenesis + 1;
return Emission.Premine;
}
if (h < Emission.Drop0)
{
hEnd = Rules::HeightGenesis + Emission.Drop0;
Expand Down
15 changes: 14 additions & 1 deletion core/block_crypt.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ namespace grimm
COMPARISON_VIA_CMP
};

struct Asset // Serialization structure
{
Key::IDV m_IDV;
AssetID m_AssetID;
bool m_Public;
};

struct Rules
{
Rules();
Expand All @@ -98,6 +105,7 @@ namespace grimm

struct {
// emission parameters
Amount Premine = Coin * 100; // Pre-mine for CAC, default 100*Coin (no premine for Grimm)
Amount Value0 = Coin * 100; // Initial emission. Each drop it will be halved. In case of odd num it's rounded to the lower value.
Height Drop0 = 1440 * 365; // 1 year roughly. This is the height of the last block that still has the initial emission, the drop is starting from the next block
Height Drop1 = 1440 * 365 * 4; // 4 years roughly. Each such a cycle there's a new drop
Expand Down Expand Up @@ -135,8 +143,13 @@ namespace grimm
} Macroblock;

size_t MaxBodySize = 0x200000; // 2MB
bool isAssetchain = false;
bool isGrimmPOW = true;
std::string CoinSymbol = "XGM"; //by default
Height TMS = 0; //Treasury MaturityStep for Assetchains in heights, default 0
uint32_t MB = 0; //Treasury steps quantity, default 0

bool AllowPublicUtxos = false;
bool AllowPublicUtxos = false;
bool FakePoW = false;

ECC::Hash::Value Prehistoric; // Prev hash of the 1st block
Expand Down
1 change: 1 addition & 0 deletions core/block_validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ namespace grimm
assert(m_Coinbase == Zero); // must have already been checked

AmountBig::AddTo(m_Sigma, m_Fee);
std::cout << __FUNCTION__ << " m_Sigma " << m_Sigma << "\n";
return m_Sigma == Zero;
}

Expand Down
23 changes: 22 additions & 1 deletion core/serialization_adapters.h
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,27 @@ namespace detail
/// Common Grimm serialization adapters
///////////////////////////////////////////////////////////

/// grimm::Asset serialization
template<typename Archive>
static Archive& save(Archive& ar, const grimm::Asset& asset)
{
ar
& asset.m_IDV
& asset.m_AssetID;

return ar;
}

template<typename Archive>
static Archive& load(Archive& ar, grimm::Asset& asset)
{
ar
& asset.m_IDV
& asset.m_AssetID;

return ar;
}

/// grimm::Input serialization
template<typename Archive>
static Archive& save(Archive& ar, const grimm::Input& input)
Expand Down Expand Up @@ -834,7 +855,7 @@ namespace detail
{
grimm::uintBigFor<uint32_t>::Type x;
ar & x;

uint32_t nSize;
x.Export(nSize);

Expand Down
5 changes: 2 additions & 3 deletions core/treasury.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,8 @@ namespace grimm
struct Parameters
{
Height m_Maturity0 = 0;
Height m_MaturityStep = 0; // 1 month roughly
uint32_t m_Bursts = 0; // 5 years plan

Height m_MaturityStep = Rules::get().TMS; // 0
uint32_t m_Bursts = Rules::get().MB; // 0
};

struct Entry
Expand Down
4 changes: 2 additions & 2 deletions core/uintBig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ namespace grimm {
return v + ((v < 10) ? '0' : ('a' - 10));
}

void uintBigImpl::_Print(const uint8_t* pDst, uint32_t nDst, std::ostream& s)
void uintBigImpl::_Print(const uint8_t* pDst, uint32_t nDst, std::ostream& s) //print all
{
const uint32_t nDigitsMax = 8;
const uint32_t nDigitsMax = 32;
if (nDst > nDigitsMax)
nDst = nDigitsMax; // truncate

Expand Down
22 changes: 18 additions & 4 deletions grimm/cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,22 @@ int main_impl(int argc, char* argv[])
clean_old_logfiles(LOG_FILES_DIR, LOG_FILES_PREFIX, logCleanupPeriod);

Rules::get().UpdateChecksum();
auto port = vm[cli::PORT].as<uint16_t>();

if (Rules::get().isAssetchain) {
LOG_INFO() << "Confidential Assetchain Symbol: " << vm[cli::CAC_SYMBOL].as<string>();
LOG_INFO() << vm[cli::CAC_SYMBOL].as<string>() << " Node " << PROJECT_VERSION << " (" << BRANCH_NAME << ")";
port = vm[cli::CAC_PORT].as<uint16_t>();


} else {
LOG_INFO() << "Grimm Node " << PROJECT_VERSION << " (" << BRANCH_NAME << ")";
LOG_INFO() << "Rules signature: " << Rules::get().get_SignatureStr();

auto port = vm[cli::PORT].as<uint16_t>();
}

LOG_INFO() << "Rules signature: " << Rules::get().get_SignatureStr();
//LOG_INFO() << Rules::get().CoinSymbol;
//LOG_INFO() << Rules::get().DA.Difficulty0;
if (!port)
{
LOG_ERROR() << "Port must be specified";
Expand Down Expand Up @@ -228,8 +239,11 @@ int main_impl(int argc, char* argv[])

node.m_Cfg.m_Listen.port(port);
node.m_Cfg.m_Listen.ip(INADDR_ANY);
node.m_Cfg.m_sPathLocal = vm[cli::STORAGE].as<string>();

if (Rules::get().isAssetchain) {
node.m_Cfg.m_sPathLocal = vm[cli::CAC_SYMBOL].as<string>() + "_" + vm[cli::STORAGE].as<string>();
} else {
node.m_Cfg.m_sPathLocal = vm[cli::STORAGE].as<string>();
}
node.m_Cfg.m_MiningThreads = vm[cli::MINING_THREADS].as<uint32_t>();

node.m_Cfg.m_VerificationThreads = vm[cli::VERIFICATION_THREADS].as<int>();
Expand Down
50 changes: 48 additions & 2 deletions grimm/grimm-node.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,51 @@
# password for keys
# pass

# Fork1 height
# Fork1=
################################################################################
# Confidential Assetchains (CAC) options:
################################################################################

# Assetchain symbol/ticker
# cac_symbol=

# Assetchain port to start the server on
# cac_port=

# Assetchain pre-mine at 1st block in the smallest unit of the coin (1 coin = 10^8 units)
# cac_premine=

# Assetchain initial coinbase emission in a single block in the smallest unit of the coin (1 coin = 10^8 units)
# cac_blockreward=

# Assetchain height of the last block that still has the initial emission, the drop is starting from the next block
# cac_drop0=

# Each such a cycle there's a new halving (in heights)
# cac_drop1=

# Coinbase coins can spend after blocks
# cac_coinbasematurity=

# Standart coins can spend after blocks
# cac_standartmaturity=

# Blocksize
# cac_blocksize=

# Block time in sec
# cac_blocktime=

# Timestamps ahead by more than FTL won't be accepted (in sec)
# cac_ftl=

# Start difficulty, default 2^1 (set 0 for start cpu mining)
# cac_diff=

# Non-confidential regular UTXO (default 'false', to switch on - 'true')
# cac_publicutxo=

# Enable assets
# asset_enabled=

# Asset exchange in main coins
# asset_exchange=
Loading

0 comments on commit 4d2c7ea

Please sign in to comment.