Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
valiant1x committed Mar 19, 2018
2 parents cbb6ba6 + 4399c4b commit d3d0f56
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: cpp
branches:
only:
- xmr
- master
matrix:
include:

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[![Build Status](https://travis-ci.org/valiant1x/intensecoin.svg?branch=master)](https://travis-ci.org/valiant1x/intensecoin)

# Intense Coin

Portions Copyright (c) 2018, The Intense Coin developers
Expand Down
11 changes: 9 additions & 2 deletions src/blockchain_db/lmdb/db_lmdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,12 @@ mdb_txn_safe::~mdb_txn_safe()
num_active_txns--;
}

void mdb_txn_safe::uncheck()
{
num_active_txns--;
m_check = false;
}

void mdb_txn_safe::commit(std::string message)
{
if (message.size() == 0)
Expand Down Expand Up @@ -1419,9 +1425,10 @@ void BlockchainLMDB::unlock()
#define TXN_PREFIX_RDONLY() \
MDB_txn *m_txn; \
mdb_txn_cursors *m_cursors; \
mdb_txn_safe auto_txn; \
bool my_rtxn = block_rtxn_start(&m_txn, &m_cursors); \
mdb_txn_safe auto_txn(my_rtxn); \
if (my_rtxn) auto_txn.m_tinfo = m_tinfo.get()
if (my_rtxn) auto_txn.m_tinfo = m_tinfo.get(); \
else auto_txn.uncheck()
#define TXN_POSTFIX_RDONLY()

#define TXN_POSTFIX_SUCCESS() \
Expand Down
1 change: 1 addition & 0 deletions src/blockchain_db/lmdb/db_lmdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ struct mdb_txn_safe
// BlockchainLMDB destructor to call mdb_txn_safe destructor, as that's too late
// to properly abort, since mdb_env_close would have been called earlier.
void abort();
void uncheck();

operator MDB_txn*()
{
Expand Down
52 changes: 34 additions & 18 deletions src/cryptonote_basic/cryptonote_basic.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ namespace cryptonote
// tx information
size_t version;
uint64_t unlock_time; //number of block (or time), used as a limitation like: spend this tx not early then block/time
bool is_mm_tx;

std::vector<txin_v> vin;
std::vector<tx_out> vout;
Expand All @@ -179,7 +180,7 @@ namespace cryptonote

BEGIN_SERIALIZE()
VARINT_FIELD(version)
if(version == 0 || CURRENT_TRANSACTION_VERSION < version) return false;
if(version == 0 || (CURRENT_TRANSACTION_VERSION < version && !is_mm_tx)) return false;
VARINT_FIELD(unlock_time)
FIELD(vin)
FIELD(vout)
Expand Down Expand Up @@ -231,8 +232,10 @@ namespace cryptonote
ar.begin_array();
PREPARE_CUSTOM_VECTOR_SERIALIZATION(vin.size(), signatures);
bool signatures_not_expected = signatures.empty();
if (!signatures_not_expected && vin.size() != signatures.size())
return false;
if (!signatures_not_expected && vin.size() != signatures.size()) {
MERROR("Failed TX sig check");
return false;
}

for (size_t i = 0; i < vin.size(); ++i)
{
Expand All @@ -246,8 +249,10 @@ namespace cryptonote
}

PREPARE_CUSTOM_VECTOR_SERIALIZATION(signature_size, signatures[i]);
if (signature_size != signatures[i].size())
return false;
if (signature_size != signatures[i].size()) {
MERROR("Failed TX size check");
return false;
}

FIELDS(signatures[i]);

Expand Down Expand Up @@ -288,6 +293,7 @@ namespace cryptonote
}
else
{
MWARNING("Processing RCT tx ..");
ar.tag("rct_signatures");
if (!vin.empty())
{
Expand Down Expand Up @@ -322,6 +328,7 @@ namespace cryptonote
{
version = 1;
unlock_time = 0;
is_mm_tx = false;
vin.clear();
vout.clear();
extra.clear();
Expand Down Expand Up @@ -357,7 +364,7 @@ namespace cryptonote
/************************************************************************/
/* */
/************************************************************************/
const uint8_t CURRENT_BYTECOIN_BLOCK_MAJOR_VERSION = 3;
const uint8_t CURRENT_BYTECOIN_BLOCK_MAJOR_VERSION = BLOCK_MAJOR_VERSION_3;

struct bytecoin_block
{
Expand All @@ -381,14 +388,11 @@ namespace cryptonote
serializable_bytecoin_block(bytecoin_block& b_, uint64_t& timestamp_, bool hashing_serialization_, bool header_only_) :
b(b_), timestamp(timestamp_), hashing_serialization(hashing_serialization_), header_only(header_only_)
{
b.miner_tx.is_mm_tx = true;
}

BEGIN_SERIALIZE_OBJECT()
VARINT_FIELD_N("major_version", b.major_version);
if (b.major_version > CURRENT_BYTECOIN_BLOCK_MAJOR_VERSION) {
MDEBUG("Bailing on bytecoin block serialization due to version; " << (unsigned)b.major_version << " > " << (unsigned)CURRENT_BYTECOIN_BLOCK_MAJOR_VERSION);
return false;
}
VARINT_FIELD_N("major_version", b.major_version);
VARINT_FIELD_N("minor_version", b.minor_version);
VARINT_FIELD(timestamp);
FIELD_N("prev_id", b.prev_id);
Expand All @@ -397,25 +401,31 @@ namespace cryptonote
if (hashing_serialization)
{
crypto::hash miner_tx_hash;
if (!get_transaction_hash(b.miner_tx, miner_tx_hash))
if (!get_transaction_hash(b.miner_tx, miner_tx_hash)) {
MERROR("Failed to get transaction hash for miner tx");
return false;
}
crypto::hash merkle_root;
crypto::tree_hash_from_branch(b.miner_tx_branch.data(), b.miner_tx_branch.size(), miner_tx_hash, 0, merkle_root);

FIELD(merkle_root);
}
VARINT_FIELD_N("number_of_transactions", b.number_of_transactions);
if (b.number_of_transactions < 1)
if (b.number_of_transactions < 1) {
MERROR("Num tx < 1?");
return false;
}

if (!header_only)
{
ar.tag("miner_tx_branch");
ar.begin_array();
size_t branch_size = crypto::tree_depth(b.number_of_transactions);
PREPARE_CUSTOM_VECTOR_SERIALIZATION(branch_size, const_cast<bytecoin_block&>(b).miner_tx_branch);
if (b.miner_tx_branch.size() != branch_size)
if (b.miner_tx_branch.size() != branch_size) {
MERROR("Miner tx branch size != branch size");
return false;
}
for (size_t i = 0; i < branch_size; ++i)
{
FIELDS(b.miner_tx_branch[i]);
Expand All @@ -427,14 +437,18 @@ namespace cryptonote
FIELD(b.miner_tx);

tx_extra_merge_mining_tag mm_tag;
if (!get_mm_tag_from_extra(b.miner_tx.extra, mm_tag))
if (!get_mm_tag_from_extra(b.miner_tx.extra, mm_tag)) {
MERROR("Failed to get mm tag from extra.");
return false;
}

ar.tag("blockchain_branch");
ar.begin_array();
PREPARE_CUSTOM_VECTOR_SERIALIZATION(mm_tag.depth, const_cast<bytecoin_block&>(b).blockchain_branch);
if (mm_tag.depth != b.blockchain_branch.size())
if (mm_tag.depth != b.blockchain_branch.size()) {
MERROR("Mm tag depth != blockchian_branch size");
return false;
}
for (size_t i = 0; i < mm_tag.depth; ++i)
{
FIELDS(b.blockchain_branch[i]);
Expand All @@ -459,7 +473,10 @@ namespace cryptonote

BEGIN_SERIALIZE()
VARINT_FIELD(major_version)
if (major_version > BLOCK_MAJOR_VERSION_3) return false;
if (major_version > BLOCK_MAJOR_VERSION_3) {
MERROR("Block version is too high " << (unsigned)major_version);
return false;
}
VARINT_FIELD(minor_version)
if (BLOCK_MAJOR_VERSION_1 == major_version)
VARINT_FIELD(timestamp)
Expand Down Expand Up @@ -493,7 +510,6 @@ namespace cryptonote
BEGIN_SERIALIZE_OBJECT()
if (!typename Archive<W>::is_saving())
set_hash_valid(false);

FIELDS(*static_cast<block_header *>(this))
if (major_version >= BLOCK_MAJOR_VERSION_2) {
auto sbb = make_serializable_bytecoin_block(*this, false, false);
Expand Down

0 comments on commit d3d0f56

Please sign in to comment.