2019-03-05 21:05:34 +00:00
|
|
|
// Copyright (c) 2014-2019, The Monero Project
|
2014-07-23 13:03:52 +00:00
|
|
|
//
|
|
|
|
// All rights reserved.
|
|
|
|
//
|
|
|
|
// Redistribution and use in source and binary forms, with or without modification, are
|
|
|
|
// permitted provided that the following conditions are met:
|
|
|
|
//
|
|
|
|
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
|
|
|
// conditions and the following disclaimer.
|
|
|
|
//
|
|
|
|
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
|
|
|
// of conditions and the following disclaimer in the documentation and/or other
|
|
|
|
// materials provided with the distribution.
|
|
|
|
//
|
|
|
|
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
|
|
|
// used to endorse or promote products derived from this software without specific
|
|
|
|
// prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
|
|
|
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
|
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
|
|
|
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
|
|
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
|
|
|
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
//
|
|
|
|
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
|
2014-03-03 22:07:58 +00:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <boost/variant.hpp>
|
|
|
|
#include <boost/functional/hash/hash.hpp>
|
|
|
|
#include <vector>
|
|
|
|
#include <cstring> // memcmp
|
|
|
|
#include <sstream>
|
2017-03-25 09:18:53 +00:00
|
|
|
#include <atomic>
|
2014-03-03 22:07:58 +00:00
|
|
|
#include "serialization/variant.h"
|
|
|
|
#include "serialization/vector.h"
|
|
|
|
#include "serialization/binary_archive.h"
|
|
|
|
#include "serialization/json_archive.h"
|
|
|
|
#include "serialization/debug_archive.h"
|
|
|
|
#include "serialization/crypto.h"
|
|
|
|
#include "serialization/keyvalue_serialization.h" // eepe named serialization
|
|
|
|
#include "cryptonote_config.h"
|
|
|
|
#include "crypto/crypto.h"
|
|
|
|
#include "crypto/hash.h"
|
|
|
|
#include "misc_language.h"
|
2016-06-15 22:37:13 +00:00
|
|
|
#include "ringct/rctTypes.h"
|
2018-03-05 07:16:30 +00:00
|
|
|
#include "device/device.hpp"
|
2014-03-03 22:07:58 +00:00
|
|
|
|
|
|
|
namespace cryptonote
|
|
|
|
{
|
|
|
|
typedef std::vector<crypto::signature> ring_signature;
|
|
|
|
|
|
|
|
|
|
|
|
/* outputs */
|
|
|
|
|
|
|
|
struct txout_to_script
|
|
|
|
{
|
|
|
|
std::vector<crypto::public_key> keys;
|
|
|
|
std::vector<uint8_t> script;
|
|
|
|
|
|
|
|
BEGIN_SERIALIZE_OBJECT()
|
|
|
|
FIELD(keys)
|
|
|
|
FIELD(script)
|
|
|
|
END_SERIALIZE()
|
|
|
|
};
|
|
|
|
|
|
|
|
struct txout_to_scripthash
|
|
|
|
{
|
|
|
|
crypto::hash hash;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct txout_to_key
|
|
|
|
{
|
|
|
|
txout_to_key() { }
|
|
|
|
txout_to_key(const crypto::public_key &_key) : key(_key) { }
|
|
|
|
crypto::public_key key;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* inputs */
|
|
|
|
|
|
|
|
struct txin_gen
|
|
|
|
{
|
|
|
|
size_t height;
|
|
|
|
|
|
|
|
BEGIN_SERIALIZE_OBJECT()
|
|
|
|
VARINT_FIELD(height)
|
|
|
|
END_SERIALIZE()
|
|
|
|
};
|
|
|
|
|
|
|
|
struct txin_to_script
|
|
|
|
{
|
|
|
|
crypto::hash prev;
|
|
|
|
size_t prevout;
|
|
|
|
std::vector<uint8_t> sigset;
|
|
|
|
|
|
|
|
BEGIN_SERIALIZE_OBJECT()
|
|
|
|
FIELD(prev)
|
|
|
|
VARINT_FIELD(prevout)
|
|
|
|
FIELD(sigset)
|
|
|
|
END_SERIALIZE()
|
|
|
|
};
|
|
|
|
|
|
|
|
struct txin_to_scripthash
|
|
|
|
{
|
|
|
|
crypto::hash prev;
|
|
|
|
size_t prevout;
|
|
|
|
txout_to_script script;
|
|
|
|
std::vector<uint8_t> sigset;
|
|
|
|
|
|
|
|
BEGIN_SERIALIZE_OBJECT()
|
|
|
|
FIELD(prev)
|
|
|
|
VARINT_FIELD(prevout)
|
|
|
|
FIELD(script)
|
|
|
|
FIELD(sigset)
|
|
|
|
END_SERIALIZE()
|
|
|
|
};
|
|
|
|
|
|
|
|
struct txin_to_key
|
|
|
|
{
|
|
|
|
uint64_t amount;
|
|
|
|
std::vector<uint64_t> key_offsets;
|
|
|
|
crypto::key_image k_image; // double spending protection
|
|
|
|
|
|
|
|
BEGIN_SERIALIZE_OBJECT()
|
|
|
|
VARINT_FIELD(amount)
|
|
|
|
FIELD(key_offsets)
|
|
|
|
FIELD(k_image)
|
|
|
|
END_SERIALIZE()
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
typedef boost::variant<txin_gen, txin_to_script, txin_to_scripthash, txin_to_key> txin_v;
|
|
|
|
|
|
|
|
typedef boost::variant<txout_to_script, txout_to_scripthash, txout_to_key> txout_target_v;
|
|
|
|
|
|
|
|
//typedef std::pair<uint64_t, txout> out_t;
|
|
|
|
struct tx_out
|
|
|
|
{
|
|
|
|
uint64_t amount;
|
|
|
|
txout_target_v target;
|
|
|
|
|
|
|
|
BEGIN_SERIALIZE_OBJECT()
|
|
|
|
VARINT_FIELD(amount)
|
|
|
|
FIELD(target)
|
|
|
|
END_SERIALIZE()
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2018-11-11 13:39:00 +00:00
|
|
|
template<typename T> static inline unsigned int getpos(T &ar) { return 0; }
|
|
|
|
template<> inline unsigned int getpos(binary_archive<true> &ar) { return ar.stream().tellp(); }
|
|
|
|
template<> inline unsigned int getpos(binary_archive<false> &ar) { return ar.stream().tellg(); }
|
|
|
|
|
2014-03-03 22:07:58 +00:00
|
|
|
class transaction_prefix
|
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
|
|
|
// 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
|
|
|
|
|
|
|
|
std::vector<txin_v> vin;
|
|
|
|
std::vector<tx_out> vout;
|
|
|
|
//extra
|
|
|
|
std::vector<uint8_t> extra;
|
|
|
|
|
|
|
|
BEGIN_SERIALIZE()
|
|
|
|
VARINT_FIELD(version)
|
2016-06-15 22:37:13 +00:00
|
|
|
if(version == 0 || CURRENT_TRANSACTION_VERSION < version) return false;
|
2014-03-03 22:07:58 +00:00
|
|
|
VARINT_FIELD(unlock_time)
|
|
|
|
FIELD(vin)
|
|
|
|
FIELD(vout)
|
|
|
|
FIELD(extra)
|
|
|
|
END_SERIALIZE()
|
|
|
|
|
2016-08-06 18:19:25 +00:00
|
|
|
public:
|
2018-11-30 14:54:46 +00:00
|
|
|
transaction_prefix(){ set_null(); }
|
|
|
|
void set_null()
|
|
|
|
{
|
|
|
|
version = 1;
|
|
|
|
unlock_time = 0;
|
|
|
|
vin.clear();
|
|
|
|
vout.clear();
|
|
|
|
extra.clear();
|
|
|
|
}
|
2014-03-03 22:07:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class transaction: public transaction_prefix
|
|
|
|
{
|
2017-03-25 09:18:53 +00:00
|
|
|
private:
|
|
|
|
// hash cash
|
|
|
|
mutable std::atomic<bool> hash_valid;
|
|
|
|
mutable std::atomic<bool> blob_size_valid;
|
|
|
|
|
2014-03-03 22:07:58 +00:00
|
|
|
public:
|
|
|
|
std::vector<std::vector<crypto::signature> > signatures; //count signatures always the same as inputs count
|
2016-06-15 22:37:13 +00:00
|
|
|
rct::rctSig rct_signatures;
|
2014-03-03 22:07:58 +00:00
|
|
|
|
2017-03-22 18:01:09 +00:00
|
|
|
// hash cash
|
|
|
|
mutable crypto::hash hash;
|
|
|
|
mutable size_t blob_size;
|
|
|
|
|
Pruning
The blockchain prunes seven eighths of prunable tx data.
This saves about two thirds of the blockchain size, while
keeping the node useful as a sync source for an eighth
of the blockchain.
No other data is currently pruned.
There are three ways to prune a blockchain:
- run monerod with --prune-blockchain
- run "prune_blockchain" in the monerod console
- run the monero-blockchain-prune utility
The first two will prune in place. Due to how LMDB works, this
will not reduce the blockchain size on disk. Instead, it will
mark parts of the file as free, so that future data will use
that free space, causing the file to not grow until free space
grows scarce.
The third way will create a second database, a pruned copy of
the original one. Since this is a new file, this one will be
smaller than the original one.
Once the database is pruned, it will stay pruned as it syncs.
That is, there is no need to use --prune-blockchain again, etc.
2018-04-29 22:30:51 +00:00
|
|
|
bool pruned;
|
|
|
|
|
2018-11-11 13:39:00 +00:00
|
|
|
std::atomic<unsigned int> unprunable_size;
|
|
|
|
std::atomic<unsigned int> prefix_size;
|
|
|
|
|
2014-03-03 22:07:58 +00:00
|
|
|
transaction();
|
2018-11-11 13:39:00 +00:00
|
|
|
transaction(const transaction &t): transaction_prefix(t), hash_valid(false), blob_size_valid(false), signatures(t.signatures), rct_signatures(t.rct_signatures), pruned(t.pruned), unprunable_size(t.unprunable_size.load()), prefix_size(t.prefix_size.load()) { if (t.is_hash_valid()) { hash = t.hash; set_hash_valid(true); } if (t.is_blob_size_valid()) { blob_size = t.blob_size; set_blob_size_valid(true); } }
|
|
|
|
transaction &operator=(const transaction &t) { transaction_prefix::operator=(t); set_hash_valid(false); set_blob_size_valid(false); signatures = t.signatures; rct_signatures = t.rct_signatures; if (t.is_hash_valid()) { hash = t.hash; set_hash_valid(true); } if (t.is_blob_size_valid()) { blob_size = t.blob_size; set_blob_size_valid(true); } pruned = t.pruned; unprunable_size = t.unprunable_size.load(); prefix_size = t.prefix_size.load(); return *this; }
|
2014-03-03 22:07:58 +00:00
|
|
|
virtual ~transaction();
|
|
|
|
void set_null();
|
2017-03-22 18:01:09 +00:00
|
|
|
void invalidate_hashes();
|
2017-03-25 09:18:53 +00:00
|
|
|
bool is_hash_valid() const { return hash_valid.load(std::memory_order_acquire); }
|
|
|
|
void set_hash_valid(bool v) const { hash_valid.store(v,std::memory_order_release); }
|
2017-04-03 21:19:57 +00:00
|
|
|
bool is_blob_size_valid() const { return blob_size_valid.load(std::memory_order_acquire); }
|
2017-03-25 09:18:53 +00:00
|
|
|
void set_blob_size_valid(bool v) const { blob_size_valid.store(v,std::memory_order_release); }
|
2018-12-05 20:34:10 +00:00
|
|
|
void set_hash(const crypto::hash &h) { hash = h; set_hash_valid(true); }
|
|
|
|
void set_blob_size(size_t sz) { blob_size = sz; set_blob_size_valid(true); }
|
2014-03-03 22:07:58 +00:00
|
|
|
|
|
|
|
BEGIN_SERIALIZE_OBJECT()
|
2017-03-22 18:01:09 +00:00
|
|
|
if (!typename Archive<W>::is_saving())
|
|
|
|
{
|
2017-03-25 09:18:53 +00:00
|
|
|
set_hash_valid(false);
|
|
|
|
set_blob_size_valid(false);
|
2017-03-22 18:01:09 +00:00
|
|
|
}
|
|
|
|
|
2018-11-11 13:39:00 +00:00
|
|
|
const unsigned int start_pos = getpos(ar);
|
|
|
|
|
2014-03-03 22:07:58 +00:00
|
|
|
FIELDS(*static_cast<transaction_prefix *>(this))
|
|
|
|
|
2018-11-11 13:39:00 +00:00
|
|
|
if (std::is_same<Archive<W>, binary_archive<W>>())
|
|
|
|
prefix_size = getpos(ar) - start_pos;
|
|
|
|
|
2016-06-15 22:37:13 +00:00
|
|
|
if (version == 1)
|
2014-03-03 22:07:58 +00:00
|
|
|
{
|
2018-11-11 13:39:00 +00:00
|
|
|
if (std::is_same<Archive<W>, binary_archive<W>>())
|
|
|
|
unprunable_size = getpos(ar) - start_pos;
|
|
|
|
|
2016-06-15 22:37:13 +00:00
|
|
|
ar.tag("signatures");
|
|
|
|
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;
|
|
|
|
|
Pruning
The blockchain prunes seven eighths of prunable tx data.
This saves about two thirds of the blockchain size, while
keeping the node useful as a sync source for an eighth
of the blockchain.
No other data is currently pruned.
There are three ways to prune a blockchain:
- run monerod with --prune-blockchain
- run "prune_blockchain" in the monerod console
- run the monero-blockchain-prune utility
The first two will prune in place. Due to how LMDB works, this
will not reduce the blockchain size on disk. Instead, it will
mark parts of the file as free, so that future data will use
that free space, causing the file to not grow until free space
grows scarce.
The third way will create a second database, a pruned copy of
the original one. Since this is a new file, this one will be
smaller than the original one.
Once the database is pruned, it will stay pruned as it syncs.
That is, there is no need to use --prune-blockchain again, etc.
2018-04-29 22:30:51 +00:00
|
|
|
if (!pruned) for (size_t i = 0; i < vin.size(); ++i)
|
2014-03-03 22:07:58 +00:00
|
|
|
{
|
2016-06-15 22:37:13 +00:00
|
|
|
size_t signature_size = get_signature_size(vin[i]);
|
|
|
|
if (signatures_not_expected)
|
|
|
|
{
|
|
|
|
if (0 == signature_size)
|
|
|
|
continue;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
PREPARE_CUSTOM_VECTOR_SERIALIZATION(signature_size, signatures[i]);
|
|
|
|
if (signature_size != signatures[i].size())
|
2014-03-03 22:07:58 +00:00
|
|
|
return false;
|
|
|
|
|
2016-06-15 22:37:13 +00:00
|
|
|
FIELDS(signatures[i]);
|
2014-03-03 22:07:58 +00:00
|
|
|
|
2016-06-15 22:37:13 +00:00
|
|
|
if (vin.size() - i > 1)
|
|
|
|
ar.delimit_array();
|
|
|
|
}
|
|
|
|
ar.end_array();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-09-14 19:23:06 +00:00
|
|
|
ar.tag("rct_signatures");
|
|
|
|
if (!vin.empty())
|
2016-06-15 22:37:13 +00:00
|
|
|
{
|
2016-09-14 19:23:06 +00:00
|
|
|
ar.begin_object();
|
|
|
|
bool r = rct_signatures.serialize_rctsig_base(ar, vin.size(), vout.size());
|
|
|
|
if (!r || !ar.stream().good()) return false;
|
|
|
|
ar.end_object();
|
2018-11-11 13:39:00 +00:00
|
|
|
|
|
|
|
if (std::is_same<Archive<W>, binary_archive<W>>())
|
|
|
|
unprunable_size = getpos(ar) - start_pos;
|
|
|
|
|
Pruning
The blockchain prunes seven eighths of prunable tx data.
This saves about two thirds of the blockchain size, while
keeping the node useful as a sync source for an eighth
of the blockchain.
No other data is currently pruned.
There are three ways to prune a blockchain:
- run monerod with --prune-blockchain
- run "prune_blockchain" in the monerod console
- run the monero-blockchain-prune utility
The first two will prune in place. Due to how LMDB works, this
will not reduce the blockchain size on disk. Instead, it will
mark parts of the file as free, so that future data will use
that free space, causing the file to not grow until free space
grows scarce.
The third way will create a second database, a pruned copy of
the original one. Since this is a new file, this one will be
smaller than the original one.
Once the database is pruned, it will stay pruned as it syncs.
That is, there is no need to use --prune-blockchain again, etc.
2018-04-29 22:30:51 +00:00
|
|
|
if (!pruned && rct_signatures.type != rct::RCTTypeNull)
|
2016-07-10 11:57:22 +00:00
|
|
|
{
|
2016-09-14 19:23:06 +00:00
|
|
|
ar.tag("rctsig_prunable");
|
|
|
|
ar.begin_object();
|
|
|
|
r = rct_signatures.p.serialize_rctsig_prunable(ar, rct_signatures.type, vin.size(), vout.size(),
|
2017-12-12 11:08:11 +00:00
|
|
|
vin.size() > 0 && vin[0].type() == typeid(txin_to_key) ? boost::get<txin_to_key>(vin[0]).key_offsets.size() - 1 : 0);
|
2016-09-14 19:23:06 +00:00
|
|
|
if (!r || !ar.stream().good()) return false;
|
|
|
|
ar.end_object();
|
2016-07-10 11:57:22 +00:00
|
|
|
}
|
|
|
|
}
|
2014-03-03 22:07:58 +00:00
|
|
|
}
|
Pruning
The blockchain prunes seven eighths of prunable tx data.
This saves about two thirds of the blockchain size, while
keeping the node useful as a sync source for an eighth
of the blockchain.
No other data is currently pruned.
There are three ways to prune a blockchain:
- run monerod with --prune-blockchain
- run "prune_blockchain" in the monerod console
- run the monero-blockchain-prune utility
The first two will prune in place. Due to how LMDB works, this
will not reduce the blockchain size on disk. Instead, it will
mark parts of the file as free, so that future data will use
that free space, causing the file to not grow until free space
grows scarce.
The third way will create a second database, a pruned copy of
the original one. Since this is a new file, this one will be
smaller than the original one.
Once the database is pruned, it will stay pruned as it syncs.
That is, there is no need to use --prune-blockchain again, etc.
2018-04-29 22:30:51 +00:00
|
|
|
if (!typename Archive<W>::is_saving())
|
|
|
|
pruned = false;
|
2014-03-03 22:07:58 +00:00
|
|
|
END_SERIALIZE()
|
|
|
|
|
2017-02-27 20:24:39 +00:00
|
|
|
template<bool W, template <bool> class Archive>
|
|
|
|
bool serialize_base(Archive<W> &ar)
|
|
|
|
{
|
|
|
|
FIELDS(*static_cast<transaction_prefix *>(this))
|
|
|
|
|
|
|
|
if (version == 1)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ar.tag("rct_signatures");
|
|
|
|
if (!vin.empty())
|
|
|
|
{
|
|
|
|
ar.begin_object();
|
|
|
|
bool r = rct_signatures.serialize_rctsig_base(ar, vin.size(), vout.size());
|
|
|
|
if (!r || !ar.stream().good()) return false;
|
|
|
|
ar.end_object();
|
|
|
|
}
|
|
|
|
}
|
Pruning
The blockchain prunes seven eighths of prunable tx data.
This saves about two thirds of the blockchain size, while
keeping the node useful as a sync source for an eighth
of the blockchain.
No other data is currently pruned.
There are three ways to prune a blockchain:
- run monerod with --prune-blockchain
- run "prune_blockchain" in the monerod console
- run the monero-blockchain-prune utility
The first two will prune in place. Due to how LMDB works, this
will not reduce the blockchain size on disk. Instead, it will
mark parts of the file as free, so that future data will use
that free space, causing the file to not grow until free space
grows scarce.
The third way will create a second database, a pruned copy of
the original one. Since this is a new file, this one will be
smaller than the original one.
Once the database is pruned, it will stay pruned as it syncs.
That is, there is no need to use --prune-blockchain again, etc.
2018-04-29 22:30:51 +00:00
|
|
|
if (!typename Archive<W>::is_saving())
|
|
|
|
pruned = true;
|
2019-04-16 18:48:40 +00:00
|
|
|
return ar.stream().good();
|
2017-02-27 20:24:39 +00:00
|
|
|
}
|
|
|
|
|
2014-09-25 06:24:42 +00:00
|
|
|
private:
|
2014-03-03 22:07:58 +00:00
|
|
|
static size_t get_signature_size(const txin_v& tx_in);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
inline
|
|
|
|
transaction::transaction()
|
|
|
|
{
|
|
|
|
set_null();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
transaction::~transaction()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
void transaction::set_null()
|
|
|
|
{
|
2018-11-30 14:54:46 +00:00
|
|
|
transaction_prefix::set_null();
|
2014-03-03 22:07:58 +00:00
|
|
|
signatures.clear();
|
2016-08-12 17:45:07 +00:00
|
|
|
rct_signatures.type = rct::RCTTypeNull;
|
2017-03-25 09:18:53 +00:00
|
|
|
set_hash_valid(false);
|
|
|
|
set_blob_size_valid(false);
|
Pruning
The blockchain prunes seven eighths of prunable tx data.
This saves about two thirds of the blockchain size, while
keeping the node useful as a sync source for an eighth
of the blockchain.
No other data is currently pruned.
There are three ways to prune a blockchain:
- run monerod with --prune-blockchain
- run "prune_blockchain" in the monerod console
- run the monero-blockchain-prune utility
The first two will prune in place. Due to how LMDB works, this
will not reduce the blockchain size on disk. Instead, it will
mark parts of the file as free, so that future data will use
that free space, causing the file to not grow until free space
grows scarce.
The third way will create a second database, a pruned copy of
the original one. Since this is a new file, this one will be
smaller than the original one.
Once the database is pruned, it will stay pruned as it syncs.
That is, there is no need to use --prune-blockchain again, etc.
2018-04-29 22:30:51 +00:00
|
|
|
pruned = false;
|
2018-11-11 13:39:00 +00:00
|
|
|
unprunable_size = 0;
|
|
|
|
prefix_size = 0;
|
2017-03-22 18:01:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
void transaction::invalidate_hashes()
|
|
|
|
{
|
2017-03-25 09:18:53 +00:00
|
|
|
set_hash_valid(false);
|
|
|
|
set_blob_size_valid(false);
|
2014-03-03 22:07:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
size_t transaction::get_signature_size(const txin_v& tx_in)
|
|
|
|
{
|
|
|
|
struct txin_signature_size_visitor : public boost::static_visitor<size_t>
|
|
|
|
{
|
|
|
|
size_t operator()(const txin_gen& txin) const{return 0;}
|
|
|
|
size_t operator()(const txin_to_script& txin) const{return 0;}
|
|
|
|
size_t operator()(const txin_to_scripthash& txin) const{return 0;}
|
|
|
|
size_t operator()(const txin_to_key& txin) const {return txin.key_offsets.size();}
|
|
|
|
};
|
|
|
|
|
|
|
|
return boost::apply_visitor(txin_signature_size_visitor(), tx_in);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/************************************************************************/
|
|
|
|
/* */
|
|
|
|
/************************************************************************/
|
|
|
|
struct block_header
|
|
|
|
{
|
2015-10-21 18:18:00 +00:00
|
|
|
uint8_t major_version;
|
|
|
|
uint8_t minor_version; // now used as a voting mechanism, rather than how this particular block is built
|
2014-03-03 22:07:58 +00:00
|
|
|
uint64_t timestamp;
|
|
|
|
crypto::hash prev_id;
|
|
|
|
uint32_t nonce;
|
|
|
|
|
|
|
|
BEGIN_SERIALIZE()
|
2015-11-30 09:07:22 +00:00
|
|
|
VARINT_FIELD(major_version)
|
|
|
|
VARINT_FIELD(minor_version)
|
2014-03-03 22:07:58 +00:00
|
|
|
VARINT_FIELD(timestamp)
|
|
|
|
FIELD(prev_id)
|
|
|
|
FIELD(nonce)
|
|
|
|
END_SERIALIZE()
|
|
|
|
};
|
|
|
|
|
|
|
|
struct block: public block_header
|
|
|
|
{
|
2017-03-25 09:18:53 +00:00
|
|
|
private:
|
|
|
|
// hash cash
|
|
|
|
mutable std::atomic<bool> hash_valid;
|
|
|
|
|
|
|
|
public:
|
2017-03-22 18:01:09 +00:00
|
|
|
block(): block_header(), hash_valid(false) {}
|
2017-03-25 09:18:53 +00:00
|
|
|
block(const block &b): block_header(b), hash_valid(false), miner_tx(b.miner_tx), tx_hashes(b.tx_hashes) { if (b.is_hash_valid()) { hash = b.hash; set_hash_valid(true); } }
|
|
|
|
block &operator=(const block &b) { block_header::operator=(b); hash_valid = false; miner_tx = b.miner_tx; tx_hashes = b.tx_hashes; if (b.is_hash_valid()) { hash = b.hash; set_hash_valid(true); } return *this; }
|
|
|
|
void invalidate_hashes() { set_hash_valid(false); }
|
|
|
|
bool is_hash_valid() const { return hash_valid.load(std::memory_order_acquire); }
|
|
|
|
void set_hash_valid(bool v) const { hash_valid.store(v,std::memory_order_release); }
|
2017-03-22 18:01:09 +00:00
|
|
|
|
2014-03-03 22:07:58 +00:00
|
|
|
transaction miner_tx;
|
|
|
|
std::vector<crypto::hash> tx_hashes;
|
|
|
|
|
2017-03-22 18:01:09 +00:00
|
|
|
// hash cash
|
|
|
|
mutable crypto::hash hash;
|
|
|
|
|
2014-03-03 22:07:58 +00:00
|
|
|
BEGIN_SERIALIZE_OBJECT()
|
2017-03-22 18:01:09 +00:00
|
|
|
if (!typename Archive<W>::is_saving())
|
2017-03-25 09:18:53 +00:00
|
|
|
set_hash_valid(false);
|
2017-03-22 18:01:09 +00:00
|
|
|
|
2014-03-03 22:07:58 +00:00
|
|
|
FIELDS(*static_cast<block_header *>(this))
|
|
|
|
FIELD(miner_tx)
|
|
|
|
FIELD(tx_hashes)
|
2019-04-04 00:15:57 +00:00
|
|
|
if (tx_hashes.size() > CRYPTONOTE_MAX_TX_PER_BLOCK)
|
|
|
|
return false;
|
2014-03-03 22:07:58 +00:00
|
|
|
END_SERIALIZE()
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/************************************************************************/
|
|
|
|
/* */
|
|
|
|
/************************************************************************/
|
|
|
|
struct account_public_address
|
|
|
|
{
|
|
|
|
crypto::public_key m_spend_public_key;
|
|
|
|
crypto::public_key m_view_public_key;
|
|
|
|
|
|
|
|
BEGIN_SERIALIZE_OBJECT()
|
|
|
|
FIELD(m_spend_public_key)
|
|
|
|
FIELD(m_view_public_key)
|
|
|
|
END_SERIALIZE()
|
|
|
|
|
|
|
|
BEGIN_KV_SERIALIZE_MAP()
|
|
|
|
KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE(m_spend_public_key)
|
|
|
|
KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE(m_view_public_key)
|
|
|
|
END_KV_SERIALIZE_MAP()
|
2017-02-19 02:42:10 +00:00
|
|
|
|
|
|
|
bool operator==(const account_public_address& rhs) const
|
|
|
|
{
|
|
|
|
return m_spend_public_key == rhs.m_spend_public_key &&
|
|
|
|
m_view_public_key == rhs.m_view_public_key;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator!=(const account_public_address& rhs) const
|
|
|
|
{
|
|
|
|
return !(*this == rhs);
|
|
|
|
}
|
2014-03-03 22:07:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct keypair
|
|
|
|
{
|
|
|
|
crypto::public_key pub;
|
|
|
|
crypto::secret_key sec;
|
|
|
|
|
2018-02-20 16:01:27 +00:00
|
|
|
static inline keypair generate(hw::device &hwdev)
|
|
|
|
{
|
|
|
|
keypair k;
|
2018-03-05 07:16:30 +00:00
|
|
|
hwdev.generate_keys(k.pub, k.sec);
|
2018-02-20 16:01:27 +00:00
|
|
|
return k;
|
|
|
|
}
|
2014-03-03 22:07:58 +00:00
|
|
|
};
|
|
|
|
//---------------------------------------------------------------
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-02-19 02:42:10 +00:00
|
|
|
namespace std {
|
|
|
|
template <>
|
|
|
|
struct hash<cryptonote::account_public_address>
|
|
|
|
{
|
|
|
|
std::size_t operator()(const cryptonote::account_public_address& addr) const
|
|
|
|
{
|
|
|
|
// https://stackoverflow.com/a/17017281
|
|
|
|
size_t res = 17;
|
|
|
|
res = res * 31 + hash<crypto::public_key>()(addr.m_spend_public_key);
|
|
|
|
res = res * 31 + hash<crypto::public_key>()(addr.m_view_public_key);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2014-03-03 22:07:58 +00:00
|
|
|
BLOB_SERIALIZER(cryptonote::txout_to_key);
|
|
|
|
BLOB_SERIALIZER(cryptonote::txout_to_scripthash);
|
|
|
|
|
|
|
|
VARIANT_TAG(binary_archive, cryptonote::txin_gen, 0xff);
|
|
|
|
VARIANT_TAG(binary_archive, cryptonote::txin_to_script, 0x0);
|
|
|
|
VARIANT_TAG(binary_archive, cryptonote::txin_to_scripthash, 0x1);
|
|
|
|
VARIANT_TAG(binary_archive, cryptonote::txin_to_key, 0x2);
|
|
|
|
VARIANT_TAG(binary_archive, cryptonote::txout_to_script, 0x0);
|
|
|
|
VARIANT_TAG(binary_archive, cryptonote::txout_to_scripthash, 0x1);
|
|
|
|
VARIANT_TAG(binary_archive, cryptonote::txout_to_key, 0x2);
|
|
|
|
VARIANT_TAG(binary_archive, cryptonote::transaction, 0xcc);
|
|
|
|
VARIANT_TAG(binary_archive, cryptonote::block, 0xbb);
|
|
|
|
|
|
|
|
VARIANT_TAG(json_archive, cryptonote::txin_gen, "gen");
|
|
|
|
VARIANT_TAG(json_archive, cryptonote::txin_to_script, "script");
|
|
|
|
VARIANT_TAG(json_archive, cryptonote::txin_to_scripthash, "scripthash");
|
|
|
|
VARIANT_TAG(json_archive, cryptonote::txin_to_key, "key");
|
|
|
|
VARIANT_TAG(json_archive, cryptonote::txout_to_script, "script");
|
|
|
|
VARIANT_TAG(json_archive, cryptonote::txout_to_scripthash, "scripthash");
|
|
|
|
VARIANT_TAG(json_archive, cryptonote::txout_to_key, "key");
|
|
|
|
VARIANT_TAG(json_archive, cryptonote::transaction, "tx");
|
|
|
|
VARIANT_TAG(json_archive, cryptonote::block, "block");
|
|
|
|
|
|
|
|
VARIANT_TAG(debug_archive, cryptonote::txin_gen, "gen");
|
|
|
|
VARIANT_TAG(debug_archive, cryptonote::txin_to_script, "script");
|
|
|
|
VARIANT_TAG(debug_archive, cryptonote::txin_to_scripthash, "scripthash");
|
|
|
|
VARIANT_TAG(debug_archive, cryptonote::txin_to_key, "key");
|
|
|
|
VARIANT_TAG(debug_archive, cryptonote::txout_to_script, "script");
|
|
|
|
VARIANT_TAG(debug_archive, cryptonote::txout_to_scripthash, "scripthash");
|
|
|
|
VARIANT_TAG(debug_archive, cryptonote::txout_to_key, "key");
|
|
|
|
VARIANT_TAG(debug_archive, cryptonote::transaction, "tx");
|
|
|
|
VARIANT_TAG(debug_archive, cryptonote::block, "block");
|