Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Benjamin Allred
crown-core
Commits
89aa9601
Commit
89aa9601
authored
6 years ago
by
Benjamin Allred
Committed by
presstab
6 years ago
Browse files
Options
Download
Email Patches
Plain Diff
BlockUndo to treat coinstake as if it were coinbase
parent
ca94b528
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
src/coins.h
+1
-1
src/coins.h
src/main.cpp
+3
-3
src/main.cpp
src/txmempool.cpp
+2
-2
src/txmempool.cpp
src/txmempool.h
+1
-1
src/txmempool.h
src/undo.h
+6
-6
src/undo.h
with
13 additions
and
13 deletions
+13
-13
src/coins.h
View file @
89aa9601
...
@@ -87,7 +87,7 @@ public:
...
@@ -87,7 +87,7 @@ public:
int
nVersion
;
int
nVersion
;
void
FromTx
(
const
CTransaction
&
tx
,
int
nHeightIn
)
{
void
FromTx
(
const
CTransaction
&
tx
,
int
nHeightIn
)
{
fBlockReward
=
tx
.
IsCoinBase
();
fBlockReward
=
tx
.
IsCoinBase
()
||
tx
.
IsCoinStake
()
;
vout
=
tx
.
vout
;
vout
=
tx
.
vout
;
nHeight
=
nHeightIn
;
nHeight
=
nHeightIn
;
nVersion
=
tx
.
nVersion
;
nVersion
=
tx
.
nVersion
;
...
...
This diff is collapsed.
Click to expand it.
src/main.cpp
View file @
89aa9601
...
@@ -1831,7 +1831,7 @@ void UpdateCoins(const CTransaction& tx, CValidationState &state, CCoinsViewCach
...
@@ -1831,7 +1831,7 @@ void UpdateCoins(const CTransaction& tx, CValidationState &state, CCoinsViewCach
if
(
coins
->
vout
.
size
()
==
0
)
{
if
(
coins
->
vout
.
size
()
==
0
)
{
CTxInUndo
&
undo
=
txundo
.
vprevout
.
back
();
CTxInUndo
&
undo
=
txundo
.
vprevout
.
back
();
undo
.
nHeight
=
coins
->
nHeight
;
undo
.
nHeight
=
coins
->
nHeight
;
undo
.
f
CoinBase
=
coins
->
fBlockReward
;
//todo - make sure undo is correct
undo
.
f
BlockReward
=
coins
->
fBlockReward
;
//todo - make sure undo is correct
undo
.
nVersion
=
coins
->
nVersion
;
undo
.
nVersion
=
coins
->
nVersion
;
}
}
}
}
...
@@ -2018,7 +2018,7 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex
...
@@ -2018,7 +2018,7 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex
if
(
!
coins
->
IsPruned
())
if
(
!
coins
->
IsPruned
())
fClean
=
fClean
&&
error
(
"DisconnectBlock() : undo data overwriting existing transaction"
);
fClean
=
fClean
&&
error
(
"DisconnectBlock() : undo data overwriting existing transaction"
);
coins
->
Clear
();
coins
->
Clear
();
coins
->
fBlockReward
=
undo
.
f
CoinBase
;
coins
->
fBlockReward
=
undo
.
f
BlockReward
;
coins
->
nHeight
=
undo
.
nHeight
;
coins
->
nHeight
=
undo
.
nHeight
;
coins
->
nVersion
=
undo
.
nVersion
;
coins
->
nVersion
=
undo
.
nVersion
;
}
else
{
}
else
{
...
@@ -2460,7 +2460,7 @@ bool static DisconnectTip(CValidationState &state) {
...
@@ -2460,7 +2460,7 @@ bool static DisconnectTip(CValidationState &state) {
if
(
tx
.
IsCoinBase
()
||
tx
.
IsCoinStake
()
||
!
AcceptToMemoryPool
(
mempool
,
stateDummy
,
tx
,
false
,
NULL
))
if
(
tx
.
IsCoinBase
()
||
tx
.
IsCoinStake
()
||
!
AcceptToMemoryPool
(
mempool
,
stateDummy
,
tx
,
false
,
NULL
))
mempool
.
remove
(
tx
,
removed
,
true
);
mempool
.
remove
(
tx
,
removed
,
true
);
}
}
mempool
.
remove
Coinbase
Spends
(
pcoinsTip
,
pindexDelete
->
nHeight
);
mempool
.
remove
BlockReward
Spends
(
pcoinsTip
,
pindexDelete
->
nHeight
);
mempool
.
check
(
pcoinsTip
);
mempool
.
check
(
pcoinsTip
);
// Update chainActive and related variables.
// Update chainActive and related variables.
UpdateTip
(
pindexDelete
->
pprev
);
UpdateTip
(
pindexDelete
->
pprev
);
...
...
This diff is collapsed.
Click to expand it.
src/txmempool.cpp
View file @
89aa9601
...
@@ -485,9 +485,9 @@ void CTxMemPool::remove(const CTransaction &origTx, std::list<CTransaction>& rem
...
@@ -485,9 +485,9 @@ void CTxMemPool::remove(const CTransaction &origTx, std::list<CTransaction>& rem
}
}
}
}
void
CTxMemPool
::
remove
Coinbase
Spends
(
const
CCoinsViewCache
*
pcoins
,
unsigned
int
nMemPoolHeight
)
void
CTxMemPool
::
remove
BlockReward
Spends
(
const
CCoinsViewCache
*
pcoins
,
unsigned
int
nMemPoolHeight
)
{
{
// Remove transactions spending a coinbase which are now immature
// Remove transactions spending a coinbase
/coinstake
which are now immature
LOCK
(
cs
);
LOCK
(
cs
);
list
<
CTransaction
>
transactionsToRemove
;
list
<
CTransaction
>
transactionsToRemove
;
for
(
std
::
map
<
uint256
,
CTxMemPoolEntry
>::
const_iterator
it
=
mapTx
.
begin
();
it
!=
mapTx
.
end
();
it
++
)
{
for
(
std
::
map
<
uint256
,
CTxMemPoolEntry
>::
const_iterator
it
=
mapTx
.
begin
();
it
!=
mapTx
.
end
();
it
++
)
{
...
...
This diff is collapsed.
Click to expand it.
src/txmempool.h
View file @
89aa9601
...
@@ -118,7 +118,7 @@ public:
...
@@ -118,7 +118,7 @@ public:
bool
addUnchecked
(
const
uint256
&
hash
,
const
CTxMemPoolEntry
&
entry
);
bool
addUnchecked
(
const
uint256
&
hash
,
const
CTxMemPoolEntry
&
entry
);
void
remove
(
const
CTransaction
&
tx
,
std
::
list
<
CTransaction
>&
removed
,
bool
fRecursive
=
false
);
void
remove
(
const
CTransaction
&
tx
,
std
::
list
<
CTransaction
>&
removed
,
bool
fRecursive
=
false
);
void
remove
Coinbase
Spends
(
const
CCoinsViewCache
*
pcoins
,
unsigned
int
nMemPoolHeight
);
void
remove
BlockReward
Spends
(
const
CCoinsViewCache
*
pcoins
,
unsigned
int
nMemPoolHeight
);
void
removeConflicts
(
const
CTransaction
&
tx
,
std
::
list
<
CTransaction
>&
removed
);
void
removeConflicts
(
const
CTransaction
&
tx
,
std
::
list
<
CTransaction
>&
removed
);
void
removeForBlock
(
const
std
::
vector
<
CTransaction
>&
vtx
,
unsigned
int
nBlockHeight
,
void
removeForBlock
(
const
std
::
vector
<
CTransaction
>&
vtx
,
unsigned
int
nBlockHeight
,
std
::
list
<
CTransaction
>&
conflicts
);
std
::
list
<
CTransaction
>&
conflicts
);
...
...
This diff is collapsed.
Click to expand it.
src/undo.h
View file @
89aa9601
...
@@ -20,22 +20,22 @@ class CTxInUndo
...
@@ -20,22 +20,22 @@ class CTxInUndo
{
{
public:
public:
CTxOut
txout
;
// the txout data before being spent
CTxOut
txout
;
// the txout data before being spent
bool
f
CoinBase
;
// if the outpoint was the last unspent: whether it belonged to a coinbase
bool
f
BlockReward
;
// if the outpoint was the last unspent: whether it belonged to a coinbase
/coinstake
unsigned
int
nHeight
;
// if the outpoint was the last unspent: its height
unsigned
int
nHeight
;
// if the outpoint was the last unspent: its height
int
nVersion
;
// if the outpoint was the last unspent: its version
int
nVersion
;
// if the outpoint was the last unspent: its version
CTxInUndo
()
:
txout
(),
f
CoinBase
(
false
),
nHeight
(
0
),
nVersion
(
0
)
{}
CTxInUndo
()
:
txout
(),
f
BlockReward
(
false
),
nHeight
(
0
),
nVersion
(
0
)
{}
CTxInUndo
(
const
CTxOut
&
txoutIn
,
bool
f
CoinBase
In
=
false
,
unsigned
int
nHeightIn
=
0
,
int
nVersionIn
=
0
)
:
txout
(
txoutIn
),
f
CoinBase
(
fCoinBase
In
),
nHeight
(
nHeightIn
),
nVersion
(
nVersionIn
)
{
}
CTxInUndo
(
const
CTxOut
&
txoutIn
,
bool
f
BlockReward
In
=
false
,
unsigned
int
nHeightIn
=
0
,
int
nVersionIn
=
0
)
:
txout
(
txoutIn
),
f
BlockReward
(
fBlockReward
In
),
nHeight
(
nHeightIn
),
nVersion
(
nVersionIn
)
{
}
unsigned
int
GetSerializeSize
(
int
nType
,
int
nVersion
)
const
{
unsigned
int
GetSerializeSize
(
int
nType
,
int
nVersion
)
const
{
return
::
GetSerializeSize
(
VARINT
(
nHeight
*
2
+
(
f
CoinBase
?
1
:
0
)),
nType
,
nVersion
)
+
return
::
GetSerializeSize
(
VARINT
(
nHeight
*
2
+
(
f
BlockReward
?
1
:
0
)),
nType
,
nVersion
)
+
(
nHeight
>
0
?
::
GetSerializeSize
(
VARINT
(
this
->
nVersion
),
nType
,
nVersion
)
:
0
)
+
(
nHeight
>
0
?
::
GetSerializeSize
(
VARINT
(
this
->
nVersion
),
nType
,
nVersion
)
:
0
)
+
::
GetSerializeSize
(
CTxOutCompressor
(
REF
(
txout
)),
nType
,
nVersion
);
::
GetSerializeSize
(
CTxOutCompressor
(
REF
(
txout
)),
nType
,
nVersion
);
}
}
template
<
typename
Stream
>
template
<
typename
Stream
>
void
Serialize
(
Stream
&
s
,
int
nType
,
int
nVersion
)
const
{
void
Serialize
(
Stream
&
s
,
int
nType
,
int
nVersion
)
const
{
::
Serialize
(
s
,
VARINT
(
nHeight
*
2
+
(
f
CoinBase
?
1
:
0
)),
nType
,
nVersion
);
::
Serialize
(
s
,
VARINT
(
nHeight
*
2
+
(
f
BlockReward
?
1
:
0
)),
nType
,
nVersion
);
if
(
nHeight
>
0
)
if
(
nHeight
>
0
)
::
Serialize
(
s
,
VARINT
(
this
->
nVersion
),
nType
,
nVersion
);
::
Serialize
(
s
,
VARINT
(
this
->
nVersion
),
nType
,
nVersion
);
::
Serialize
(
s
,
CTxOutCompressor
(
REF
(
txout
)),
nType
,
nVersion
);
::
Serialize
(
s
,
CTxOutCompressor
(
REF
(
txout
)),
nType
,
nVersion
);
...
@@ -46,7 +46,7 @@ public:
...
@@ -46,7 +46,7 @@ public:
unsigned
int
nCode
=
0
;
unsigned
int
nCode
=
0
;
::
Unserialize
(
s
,
VARINT
(
nCode
),
nType
,
nVersion
);
::
Unserialize
(
s
,
VARINT
(
nCode
),
nType
,
nVersion
);
nHeight
=
nCode
/
2
;
nHeight
=
nCode
/
2
;
f
CoinBase
=
nCode
&
1
;
f
BlockReward
=
nCode
&
1
;
if
(
nHeight
>
0
)
if
(
nHeight
>
0
)
::
Unserialize
(
s
,
VARINT
(
this
->
nVersion
),
nType
,
nVersion
);
::
Unserialize
(
s
,
VARINT
(
this
->
nVersion
),
nType
,
nVersion
);
::
Unserialize
(
s
,
REF
(
CTxOutCompressor
(
REF
(
txout
))),
nType
,
nVersion
);
::
Unserialize
(
s
,
REF
(
CTxOutCompressor
(
REF
(
txout
))),
nType
,
nVersion
);
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment