FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
sidecoin/src/checkpoints.cpp at master · superstacked/sidecoin · GitHub
superstacked
/
sidecoin
Public
forked from
glaspe/sidecoin
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
sidecoin
/
src
/
checkpoints.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
154 lines (127 loc) · 5.44 KB
Breadcrumbs
sidecoin
/
src
/
checkpoints.cpp
Copy path
File metadata and controls
154 lines (127 loc) · 5.44 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
//
Copyright (c) 2009-2014 The Bitcoin developers
//
Copyright (c) 2014 Joey Krug and Jack Peterson
//
Distributed under the MIT/X11 software license, see the accompanying
//
file COPYING or http://www.opensource.org/licenses/mit-license.php.
#
include
"
checkpoints.h
"
#
include
"
main.h
"
#
include
"
uint256.h
"
#
include
<
stdint.h
>
#
include
<
boost/assign/list_of.hpp
>
//
for 'map_list_of()'
#
include
<
boost/foreach.hpp
>
namespace
Checkpoints
{
typedef
std::map<
int
, uint256> MapCheckpoints;
//
How many times we expect transactions after the last checkpoint to
//
be slower. This number is a compromise, as it can't be accurate for
//
every system. When reindexing from a fast disk with a slow CPU, it
//
can be up to 20, while when downloading from a slow network with a
//
fast multicore CPU, it won't be much higher than 1.
static
const
double
fSigcheckVerificationFactor
=
5.0
;
struct
CCheckpointData
{
const
MapCheckpoints *mapCheckpoints;
int64_t
nTimeLastCheckpoint;
int64_t
nTransactionsLastCheckpoint;
double
fTransactionsPerDay
;
};
bool
fEnabled
=
true
;
//
What makes a good checkpoint block?
//
+ Is surrounded by blocks with reasonable timestamps
//
(no blocks before with a timestamp after, none after with
//
timestamp before)
//
+ Contains no strange transactions
static
MapCheckpoints mapCheckpoints =
boost::assign::map_list_of
(
0
, uint256(
"
0x00000000fed46bbc2172a89455873cf6794528545797ff7a013e551f6fc73ef7
"
))
(
1
, uint256(
"
00000000e5cabdb3fa5ae55a45a5473e4f05eefb48b58fc917c43b4ae57c9116
"
))
;
static
const
CCheckpointData data = {
&mapCheckpoints,
1410847826
,
//
* UNIX timestamp of last checkpoint block
0
,
//
* total number of transactions between genesis and last checkpoint
//
(the tx=... number in the SetBestChain debug.log lines)
100.0
//
* estimated number of transactions per day after checkpoint
};
static
MapCheckpoints mapCheckpointsTestnet =
boost::assign::map_list_of
(
0
, uint256(
"
000000000bf5c4f4a9cdcfe2b1423ce6b7852382f9638d0f56252ae5e14e6a68
"
))
;
static
const
CCheckpointData dataTestnet = {
&mapCheckpointsTestnet,
1412107897
,
0
,
100.0
};
static
MapCheckpoints mapCheckpointsRegtest =
boost::assign::map_list_of
(
0
, uint256(
"
0000000000ebd7ab5c8e363e0696954fc54ab6910fc98867f628efc928b8d3c7
"
))
;
static
const
CCheckpointData dataRegtest = {
&mapCheckpointsRegtest,
0
,
0
,
0
};
const
CCheckpointData &
Checkpoints
() {
if
(
Params
().
NetworkID
() == CChainParams::
TESTNET
)
return
dataTestnet;
else
if
(
Params
().
NetworkID
() == CChainParams::
MAIN
)
return
data;
else
return
dataRegtest;
}
bool
CheckBlock
(
int
nHeight,
const
uint256& hash)
{
if
(!
fEnabled
)
return
true
;
const
MapCheckpoints& checkpoints = *
Checkpoints
().
mapCheckpoints
;
MapCheckpoints::const_iterator i = checkpoints.
find
(nHeight);
if
(i == checkpoints.
end
())
return
true
;
return
hash == i->
second
;
}
//
Guess how far we are in the verification process at the given block index
double
GuessVerificationProgress
(CBlockIndex *pindex) {
if
(pindex==
NULL
)
return
0.0
;
int64_t
nNow =
time
(
NULL
);
double
fWorkBefore
=
0.0
;
//
Amount of work done before pindex
double
fWorkAfter
=
0.0
;
//
Amount of work left after pindex (estimated)
//
Work is defined as: 1.0 per transaction before the last checkpoint, and
//
fSigcheckVerificationFactor per transaction after.
const
CCheckpointData &data =
Checkpoints
();
if
(pindex->
nChainTx
<= data.
nTransactionsLastCheckpoint
) {
double
nCheapBefore = pindex->
nChainTx
;
double
nCheapAfter = data.
nTransactionsLastCheckpoint
- pindex->
nChainTx
;
double
nExpensiveAfter = (nNow - data.
nTimeLastCheckpoint
)/
86400.0
*data.
fTransactionsPerDay
;
fWorkBefore
= nCheapBefore;
fWorkAfter
= nCheapAfter + nExpensiveAfter*
fSigcheckVerificationFactor
;
}
else
{
double
nCheapBefore = data.
nTransactionsLastCheckpoint
;
double
nExpensiveBefore = pindex->
nChainTx
- data.
nTransactionsLastCheckpoint
;
double
nExpensiveAfter = (nNow - pindex->
nTime
)/
86400.0
*data.
fTransactionsPerDay
;
fWorkBefore
= nCheapBefore + nExpensiveBefore*
fSigcheckVerificationFactor
;
fWorkAfter
= nExpensiveAfter*
fSigcheckVerificationFactor
;
}
return
fWorkBefore
/ (
fWorkBefore
+
fWorkAfter
);
}
int
GetTotalBlocksEstimate
()
{
if
(!
fEnabled
)
return
0
;
const
MapCheckpoints& checkpoints = *
Checkpoints
().
mapCheckpoints
;
return
checkpoints.
rbegin
()->
first
;
}
CBlockIndex*
GetLastCheckpoint
(
const
std::map<uint256, CBlockIndex*>& mapBlockIndex)
{
if
(!
fEnabled
)
return
NULL
;
const
MapCheckpoints& checkpoints = *
Checkpoints
().
mapCheckpoints
;
BOOST_REVERSE_FOREACH
(
const
MapCheckpoints::value_type& i, checkpoints)
{
const
uint256& hash = i.
second
;
std::map<uint256, CBlockIndex*>::const_iterator t = mapBlockIndex.
find
(hash);
if
(t != mapBlockIndex.
end
())
return
t->
second
;
}
return
NULL
;
}
}
Back
|
FazBrowse Home
|
New Git URL