This repository has been archived by the owner on Oct 9, 2019. It is now read-only.
forked from bitcoin/bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 55
/
consensus.h
87 lines (67 loc) · 2.75 KB
/
consensus.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2016 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_CONSENSUS_CONSENSUS_H
#define BITCOIN_CONSENSUS_CONSENSUS_H
#include <stdint.h>
/** The maximum allowed size for a serialized block, in bytes (only for buffer size limits) */
static const unsigned int MAX_BLOCK_SERIALIZED_SIZE = (8 * 1000 * 1000);
/** The maximum allowed size for a block excluding witness data, in bytes (network rule) */
static inline bool BIP102active(bool fSegwitSeasoned)
{
return fSegwitSeasoned;
}
static const unsigned int MAX_LEGACY_BLOCK_SIZE = (1 * 1000 * 1000);
static const unsigned int MAX_BASE_BLOCK_SIZE = (2 * 1000 * 1000);
inline unsigned int MaxBlockBaseSize(bool fSegwitSeasoned)
{
if (!BIP102active(fSegwitSeasoned))
return MAX_LEGACY_BLOCK_SIZE;
return MAX_BASE_BLOCK_SIZE;
}
inline unsigned int MaxBlockBaseSize()
{
return MaxBlockBaseSize(true);
}
/** The maximum allowed number of signature check operations in a block (network rule) */
static const uint64_t MAX_BLOCK_BASE_SIGOPS = 20000;
inline int64_t MaxBlockSigOpsCost(bool fSegwitSeasoned)
{
if (!BIP102active(fSegwitSeasoned))
return (MAX_BLOCK_BASE_SIGOPS * 4 /* WITNESS_SCALE_FACTOR */);
return ((2 * MAX_BLOCK_BASE_SIGOPS) * 4 /* WITNESS_SCALE_FACTOR */);
}
inline int64_t MaxBlockSigOpsCost()
{
return MaxBlockSigOpsCost(true);
}
/** The maximum allowed weight for a block, see BIP 141 (network rule) */
inline unsigned int MaxBlockWeight(bool fSegwitSeasoned)
{
return (MaxBlockBaseSize(fSegwitSeasoned) * 4 /* WITNESS_SCALE_FACTOR */);
}
inline unsigned int MaxBlockWeight()
{
return MaxBlockWeight(true);
}
inline unsigned int MaxBlockSerSize(bool fSegwitSeasoned)
{
return (MaxBlockBaseSize(fSegwitSeasoned) * 4);
}
/** The minimum allowed size for a transaction */
static const unsigned int MIN_TRANSACTION_BASE_SIZE = 10;
/** The maximum allowed size for a transaction, excluding witness data, in bytes */
static const unsigned int MAX_TX_BASE_SIZE = 1000000;
/** The maximum allowed number of transactions per block */
static const unsigned int MAX_BLOCK_VTX = MAX_BASE_BLOCK_SIZE / MIN_TRANSACTION_BASE_SIZE;
/** Coinbase transaction outputs can only be spent after this number of new blocks (network rule) */
static const int COINBASE_MATURITY = 100;
/** Flags for nSequence and nLockTime locks */
enum {
/* Interpret sequence numbers as relative lock-time constraints. */
LOCKTIME_VERIFY_SEQUENCE = (1 << 0),
/* Use GetMedianTimePast() instead of nTime for end point timestamp. */
LOCKTIME_MEDIAN_TIME_PAST = (1 << 1),
};
#endif // BITCOIN_CONSENSUS_CONSENSUS_H