Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
plugin
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
link33
plugin
Commits
25b3c68b
Unverified
Commit
25b3c68b
authored
Jun 21, 2019
by
vipwzw
Committed by
GitHub
Jun 21, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #532 from lyh169/mod_kvmvcc_rollback
Mod kvmvcc rollback
parents
c2820b66
14861d35
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
30 additions
and
90 deletions
+30
-90
kvmvccdb.go
plugin/store/kvmvcc/kvmvccdb.go
+0
-7
kvmvccdb_test.go
plugin/store/kvmvcc/kvmvccdb_test.go
+1
-1
kvmvcc_mavl_test.go
plugin/store/kvmvccmavl/kvmvcc_mavl_test.go
+1
-1
kvmvccdb.go
plugin/store/kvmvccmavl/kvmvccdb.go
+5
-7
blockstore.go
vendor/github.com/33cn/chain33/blockchain/blockstore.go
+1
-63
blockstore_test.go
vendor/github.com/33cn/chain33/blockchain/blockstore_test.go
+0
-6
chain.go
vendor/github.com/33cn/chain33/blockchain/chain.go
+0
-2
wallet.go
...or/github.com/33cn/chain33/system/dapp/commands/wallet.go
+1
-1
sendtx.go
vendor/github.com/33cn/chain33/wallet/sendtx.go
+10
-2
wallet_proc.go
vendor/github.com/33cn/chain33/wallet/wallet_proc.go
+11
-0
No files found.
plugin/store/kvmvcc/kvmvccdb.go
View file @
25b3c68b
...
@@ -16,7 +16,6 @@ import (
...
@@ -16,7 +16,6 @@ import (
)
)
var
klog
=
log
.
New
(
"module"
,
"kvmvccdb"
)
var
klog
=
log
.
New
(
"module"
,
"kvmvccdb"
)
var
maxRollbackNum
=
200
// SetLogLevel set log level
// SetLogLevel set log level
func
SetLogLevel
(
level
string
)
{
func
SetLogLevel
(
level
string
)
{
...
@@ -257,7 +256,6 @@ func (mvccs *KVMVCCStore) checkVersion(height int64) ([]*types.KeyValue, error)
...
@@ -257,7 +256,6 @@ func (mvccs *KVMVCCStore) checkVersion(height int64) ([]*types.KeyValue, error)
}
else
if
maxVersion
==
height
-
1
{
}
else
if
maxVersion
==
height
-
1
{
return
nil
,
nil
return
nil
,
nil
}
else
{
}
else
{
count
:=
1
for
i
:=
maxVersion
;
i
>=
height
;
i
--
{
for
i
:=
maxVersion
;
i
>=
height
;
i
--
{
hash
,
err
:=
mvccs
.
mvcc
.
GetVersionHash
(
i
)
hash
,
err
:=
mvccs
.
mvcc
.
GetVersionHash
(
i
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -272,11 +270,6 @@ func (mvccs *KVMVCCStore) checkVersion(height int64) ([]*types.KeyValue, error)
...
@@ -272,11 +270,6 @@ func (mvccs *KVMVCCStore) checkVersion(height int64) ([]*types.KeyValue, error)
kvset
=
append
(
kvset
,
kvlist
...
)
kvset
=
append
(
kvset
,
kvlist
...
)
klog
.
Debug
(
"store kvmvcc checkVersion DelMVCC4Height"
,
"height"
,
i
,
"maxVersion"
,
maxVersion
)
klog
.
Debug
(
"store kvmvcc checkVersion DelMVCC4Height"
,
"height"
,
i
,
"maxVersion"
,
maxVersion
)
//为避免高度差过大时出现异常,做一个保护,一次最多回滚200个区块
count
++
if
count
>=
maxRollbackNum
{
break
}
}
}
}
}
...
...
plugin/store/kvmvcc/kvmvccdb_test.go
View file @
25b3c68b
...
@@ -255,7 +255,7 @@ func TestKvmvccdbRollbackBatch(t *testing.T) {
...
@@ -255,7 +255,7 @@ func TestKvmvccdbRollbackBatch(t *testing.T) {
maxVersion
,
err
=
store
.
mvcc
.
GetMaxVersion
()
maxVersion
,
err
=
store
.
mvcc
.
GetMaxVersion
()
assert
.
Equal
(
t
,
nil
,
err
)
assert
.
Equal
(
t
,
nil
,
err
)
assert
.
Equal
(
t
,
int64
(
3
),
maxVersion
)
assert
.
Equal
(
t
,
int64
(
1
),
maxVersion
)
get2
:=
&
types
.
StoreGet
{
StateHash
:
hash
,
Keys
:
keys
}
get2
:=
&
types
.
StoreGet
{
StateHash
:
hash
,
Keys
:
keys
}
values2
:=
store
.
Get
(
get2
)
values2
:=
store
.
Get
(
get2
)
...
...
plugin/store/kvmvccmavl/kvmvcc_mavl_test.go
View file @
25b3c68b
...
@@ -363,7 +363,7 @@ func TestKvmvccdbRollbackBatch(t *testing.T) {
...
@@ -363,7 +363,7 @@ func TestKvmvccdbRollbackBatch(t *testing.T) {
maxVersion
,
err
=
store
.
mvcc
.
GetMaxVersion
()
maxVersion
,
err
=
store
.
mvcc
.
GetMaxVersion
()
assert
.
Equal
(
t
,
nil
,
err
)
assert
.
Equal
(
t
,
nil
,
err
)
assert
.
Equal
(
t
,
int64
(
3
),
maxVersion
)
assert
.
Equal
(
t
,
int64
(
1
),
maxVersion
)
get2
:=
&
types
.
StoreGet
{
StateHash
:
hash
,
Keys
:
keys
}
get2
:=
&
types
.
StoreGet
{
StateHash
:
hash
,
Keys
:
keys
}
values2
:=
store
.
Get
(
get2
)
values2
:=
store
.
Get
(
get2
)
...
...
plugin/store/kvmvccmavl/kvmvccdb.go
View file @
25b3c68b
...
@@ -10,6 +10,8 @@ import (
...
@@ -10,6 +10,8 @@ import (
"strconv"
"strconv"
"sync/atomic"
"sync/atomic"
"time"
"github.com/33cn/chain33/common"
"github.com/33cn/chain33/common"
dbm
"github.com/33cn/chain33/common/db"
dbm
"github.com/33cn/chain33/common/db"
"github.com/33cn/chain33/queue"
"github.com/33cn/chain33/queue"
...
@@ -26,7 +28,6 @@ const (
...
@@ -26,7 +28,6 @@ const (
)
)
var
(
var
(
maxRollbackNum
=
200
// 是否开启裁剪
// 是否开启裁剪
enablePrune
bool
enablePrune
bool
// 每个10000裁剪一次
// 每个10000裁剪一次
...
@@ -294,7 +295,6 @@ func (mvccs *KVMVCCStore) checkVersion(height int64) ([]*types.KeyValue, error)
...
@@ -294,7 +295,6 @@ func (mvccs *KVMVCCStore) checkVersion(height int64) ([]*types.KeyValue, error)
}
else
if
maxVersion
==
height
-
1
{
}
else
if
maxVersion
==
height
-
1
{
return
nil
,
nil
return
nil
,
nil
}
else
{
}
else
{
count
:=
1
for
i
:=
maxVersion
;
i
>=
height
;
i
--
{
for
i
:=
maxVersion
;
i
>=
height
;
i
--
{
hash
,
err
:=
mvccs
.
mvcc
.
GetVersionHash
(
i
)
hash
,
err
:=
mvccs
.
mvcc
.
GetVersionHash
(
i
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -309,11 +309,6 @@ func (mvccs *KVMVCCStore) checkVersion(height int64) ([]*types.KeyValue, error)
...
@@ -309,11 +309,6 @@ func (mvccs *KVMVCCStore) checkVersion(height int64) ([]*types.KeyValue, error)
kvset
=
append
(
kvset
,
kvlist
...
)
kvset
=
append
(
kvset
,
kvlist
...
)
kmlog
.
Debug
(
"store kvmvcc checkVersion DelMVCC4Height"
,
"height"
,
i
,
"maxVersion"
,
maxVersion
)
kmlog
.
Debug
(
"store kvmvcc checkVersion DelMVCC4Height"
,
"height"
,
i
,
"maxVersion"
,
maxVersion
)
//为避免高度差过大时出现异常,做一个保护,一次最多回滚200个区块
count
++
if
count
>=
maxRollbackNum
{
break
}
}
}
}
}
...
@@ -345,7 +340,10 @@ func pruning(db dbm.DB, height int64) {
...
@@ -345,7 +340,10 @@ func pruning(db dbm.DB, height int64) {
func
pruningMVCC
(
db
dbm
.
DB
,
height
int64
)
{
func
pruningMVCC
(
db
dbm
.
DB
,
height
int64
)
{
setPruning
(
pruningStateStart
)
setPruning
(
pruningStateStart
)
defer
setPruning
(
pruningStateEnd
)
defer
setPruning
(
pruningStateEnd
)
start
:=
time
.
Now
()
pruningFirst
(
db
,
height
)
pruningFirst
(
db
,
height
)
end
:=
time
.
Now
()
kmlog
.
Debug
(
"pruningMVCC"
,
"height"
,
height
,
"cost"
,
end
.
Sub
(
start
))
}
}
func
pruningFirst
(
db
dbm
.
DB
,
curHeight
int64
)
{
func
pruningFirst
(
db
dbm
.
DB
,
curHeight
int64
)
{
...
...
vendor/github.com/33cn/chain33/blockchain/blockstore.go
View file @
25b3c68b
...
@@ -1242,7 +1242,6 @@ func (bs *BlockStore) SetStoreUpgradeMeta(meta *types.UpgradeMeta) error {
...
@@ -1242,7 +1242,6 @@ func (bs *BlockStore) SetStoreUpgradeMeta(meta *types.UpgradeMeta) error {
const
(
const
(
seqStatusOk
=
iota
seqStatusOk
=
iota
seqStatusNeedCreate
seqStatusNeedCreate
seqStatusNeedDelete
)
)
//CheckSequenceStatus 配置的合法性检测
//CheckSequenceStatus 配置的合法性检测
...
@@ -1267,25 +1266,12 @@ func (bs *BlockStore) CheckSequenceStatus(recordSequence bool) int {
...
@@ -1267,25 +1266,12 @@ func (bs *BlockStore) CheckSequenceStatus(recordSequence bool) int {
storeLog
.
Error
(
"CheckSequenceStatus"
,
"lastHeight"
,
lastHeight
,
"lastSequence"
,
lastSequence
)
storeLog
.
Error
(
"CheckSequenceStatus"
,
"lastHeight"
,
lastHeight
,
"lastSequence"
,
lastSequence
)
return
seqStatusNeedCreate
return
seqStatusNeedCreate
}
}
//通过lastSequence获取对应的blockhash != lastHeader.hash 报错
if
lastSequence
!=
-
1
{
blockSequence
,
err
:=
bs
.
GetBlockSequence
(
lastSequence
)
if
err
!=
nil
{
storeLog
.
Error
(
"CheckSequenceStatus"
,
"lastSequence"
,
lastSequence
,
"GetBlockSequence err"
,
err
)
panic
(
err
)
}
lastHeader
:=
bs
.
LastHeader
()
if
!
bytes
.
Equal
(
lastHeader
.
Hash
,
blockSequence
.
Hash
)
{
storeLog
.
Error
(
"CheckSequenceStatus:"
,
"lastHeight"
,
lastHeight
,
"lastSequence"
,
lastSequence
,
"lastHeader.Hash"
,
common
.
ToHex
(
lastHeader
.
Hash
),
"blockSequence.Hash"
,
common
.
ToHex
(
blockSequence
.
Hash
))
return
seqStatusNeedCreate
}
}
return
seqStatusOk
return
seqStatusOk
}
}
//去使能isRecordBlockSequence时的检测
//去使能isRecordBlockSequence时的检测
if
lastSequence
!=
-
1
{
if
lastSequence
!=
-
1
{
storeLog
.
Error
(
"CheckSequenceStatus"
,
"lastSequence"
,
lastSequence
)
storeLog
.
Error
(
"CheckSequenceStatus"
,
"lastSequence"
,
lastSequence
)
return
seqStatusNeedDelete
panic
(
"can not disable isRecordBlockSequence"
)
}
}
return
seqStatusOk
return
seqStatusOk
}
}
...
@@ -1348,51 +1334,3 @@ func (bs *BlockStore) CreateSequences(batchSize int64) {
...
@@ -1348,51 +1334,3 @@ func (bs *BlockStore) CreateSequences(batchSize int64) {
}
}
storeLog
.
Info
(
"CreateSequences done"
)
storeLog
.
Info
(
"CreateSequences done"
)
}
}
//DeleteSequences 删除本地数据库里的sequence记录
func
(
bs
*
BlockStore
)
DeleteSequences
(
batchSize
int64
)
{
lastSeq
,
err
:=
bs
.
LoadBlockLastSequence
()
if
err
!=
nil
{
if
err
!=
types
.
ErrHeightNotExist
{
storeLog
.
Error
(
"DeleteSequences LoadBlockLastSequence"
,
"error"
,
err
)
panic
(
"DeleteSequences LoadBlockLastSequence"
+
err
.
Error
())
}
}
storeLog
.
Info
(
"DeleteSequences LoadBlockLastSequence"
,
"start"
,
lastSeq
)
newBatch
:=
bs
.
NewBatch
(
true
)
for
i
:=
lastSeq
;
i
>=
0
;
i
--
{
seq
:=
i
header
,
err
:=
bs
.
GetBlockHeaderByHeight
(
i
)
if
err
!=
nil
{
storeLog
.
Error
(
"DeleteSequences GetBlockHeaderByHeight"
,
"height"
,
i
,
"error"
,
err
)
panic
(
"DeleteSequences GetBlockHeaderByHeight"
+
err
.
Error
())
}
// seq->hash
newBatch
.
Delete
(
calcSequenceToHashKey
(
seq
,
bs
.
isParaChain
))
// hash -> seq
newBatch
.
Delete
(
calcHashToSequenceKey
(
header
.
Hash
,
bs
.
isParaChain
))
if
lastSeq
-
i
==
batchSize
{
storeLog
.
Info
(
"DeleteSequences "
,
"height"
,
i
)
newBatch
.
Set
(
calcLastSeqKey
(
bs
.
isParaChain
),
types
.
Encode
(
&
types
.
Int64
{
Data
:
i
-
1
}))
err
=
newBatch
.
Write
()
if
err
!=
nil
{
storeLog
.
Error
(
"DeleteSequences newBatch.Write"
,
"error"
,
err
)
panic
(
"DeleteSequences newBatch.Write"
+
err
.
Error
())
}
lastSeq
=
i
-
1
newBatch
.
Reset
()
}
}
// last seq
newBatch
.
Delete
(
calcLastSeqKey
(
bs
.
isParaChain
))
err
=
newBatch
.
Write
()
if
err
!=
nil
{
storeLog
.
Error
(
"DeleteSequences newBatch.Write"
,
"error"
,
err
)
panic
(
"DeleteSequences newBatch.Write"
+
err
.
Error
())
}
storeLog
.
Info
(
"DeleteSequences done"
)
}
vendor/github.com/33cn/chain33/blockchain/blockstore_test.go
View file @
25b3c68b
...
@@ -176,10 +176,4 @@ func TestSeqCreateAndDelete(t *testing.T) {
...
@@ -176,10 +176,4 @@ func TestSeqCreateAndDelete(t *testing.T) {
seq
,
err
=
blockStore
.
GetSequenceByHash
([]
byte
(
"0"
))
seq
,
err
=
blockStore
.
GetSequenceByHash
([]
byte
(
"0"
))
assert
.
Nil
(
t
,
err
)
assert
.
Nil
(
t
,
err
)
assert
.
Equal
(
t
,
int64
(
0
),
seq
)
assert
.
Equal
(
t
,
int64
(
0
),
seq
)
blockStore
.
saveSequence
=
false
blockStore
.
DeleteSequences
(
10
)
seq
,
err
=
blockStore
.
LoadBlockLastSequence
()
assert
.
NotNil
(
t
,
err
)
assert
.
Equal
(
t
,
int64
(
-
1
),
seq
)
}
}
vendor/github.com/33cn/chain33/blockchain/chain.go
View file @
25b3c68b
...
@@ -248,8 +248,6 @@ func (chain *BlockChain) InitBlockChain() {
...
@@ -248,8 +248,6 @@ func (chain *BlockChain) InitBlockChain() {
seqStatus
:=
chain
.
blockStore
.
CheckSequenceStatus
(
chain
.
isRecordBlockSequence
)
seqStatus
:=
chain
.
blockStore
.
CheckSequenceStatus
(
chain
.
isRecordBlockSequence
)
if
seqStatus
==
seqStatusNeedCreate
{
if
seqStatus
==
seqStatusNeedCreate
{
chain
.
blockStore
.
CreateSequences
(
100000
)
chain
.
blockStore
.
CreateSequences
(
100000
)
}
else
if
seqStatus
==
seqStatusNeedDelete
{
chain
.
blockStore
.
DeleteSequences
(
100000
)
}
}
//先缓存最新的128个block信息到cache中
//先缓存最新的128个block信息到cache中
...
...
vendor/github.com/33cn/chain33/system/dapp/commands/wallet.go
View file @
25b3c68b
...
@@ -312,7 +312,7 @@ func addSignRawTxFlags(cmd *cobra.Command) {
...
@@ -312,7 +312,7 @@ func addSignRawTxFlags(cmd *cobra.Command) {
cmd
.
Flags
()
.
StringP
(
"key"
,
"k"
,
""
,
"private key (optional)"
)
cmd
.
Flags
()
.
StringP
(
"key"
,
"k"
,
""
,
"private key (optional)"
)
cmd
.
Flags
()
.
StringP
(
"addr"
,
"a"
,
""
,
"account address (optional)"
)
cmd
.
Flags
()
.
StringP
(
"addr"
,
"a"
,
""
,
"account address (optional)"
)
cmd
.
Flags
()
.
StringP
(
"expire"
,
"e"
,
"120s"
,
"transaction expire time"
)
cmd
.
Flags
()
.
StringP
(
"expire"
,
"e"
,
"120s"
,
"transaction expire time"
)
cmd
.
Flags
()
.
Float64P
(
"fee"
,
"f"
,
0
,
"transaction fee (optional)"
)
cmd
.
Flags
()
.
Float64P
(
"fee"
,
"f"
,
0
,
"transaction fee (optional)
, auto set proper fee if not set or zero fee
"
)
cmd
.
Flags
()
.
StringP
(
"to"
,
"t"
,
""
,
"new to addr (optional)"
)
cmd
.
Flags
()
.
StringP
(
"to"
,
"t"
,
""
,
"new to addr (optional)"
)
// A duration string is a possibly signed sequence of
// A duration string is a possibly signed sequence of
...
...
vendor/github.com/33cn/chain33/wallet/sendtx.go
View file @
25b3c68b
...
@@ -117,7 +117,11 @@ func (wallet *Wallet) sendTransaction(payload types.Message, execer []byte, priv
...
@@ -117,7 +117,11 @@ func (wallet *Wallet) sendTransaction(payload types.Message, execer []byte, priv
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
tx
.
Fee
=
proper
.
ProperFee
fee
,
err
:=
tx
.
GetRealFee
(
proper
.
ProperFee
)
if
err
!=
nil
{
return
nil
,
err
}
tx
.
Fee
=
fee
tx
.
SetExpire
(
time
.
Second
*
120
)
tx
.
SetExpire
(
time
.
Second
*
120
)
tx
.
Sign
(
int32
(
SignType
),
priv
)
tx
.
Sign
(
int32
(
SignType
),
priv
)
reply
,
err
:=
wallet
.
sendTx
(
tx
)
reply
,
err
:=
wallet
.
sendTx
(
tx
)
...
@@ -231,7 +235,11 @@ func (wallet *Wallet) createSendToAddress(addrto string, amount int64, note stri
...
@@ -231,7 +235,11 @@ func (wallet *Wallet) createSendToAddress(addrto string, amount int64, note stri
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
tx
.
Fee
=
proper
.
ProperFee
fee
,
err
:=
tx
.
GetRealFee
(
proper
.
ProperFee
)
if
err
!=
nil
{
return
nil
,
err
}
tx
.
Fee
=
fee
if
tx
.
To
==
""
{
if
tx
.
To
==
""
{
tx
.
To
=
addrto
tx
.
To
=
addrto
}
}
...
...
vendor/github.com/33cn/chain33/wallet/wallet_proc.go
View file @
25b3c68b
...
@@ -86,6 +86,17 @@ func (wallet *Wallet) ProcSignRawTx(unsigned *types.ReqSignRawTx) (string, error
...
@@ -86,6 +86,17 @@ func (wallet *Wallet) ProcSignRawTx(unsigned *types.ReqSignRawTx) (string, error
}
}
if
unsigned
.
Fee
!=
0
{
if
unsigned
.
Fee
!=
0
{
tx
.
Fee
=
unsigned
.
Fee
tx
.
Fee
=
unsigned
.
Fee
}
else
{
//get proper fee if not set
proper
,
err
:=
wallet
.
api
.
GetProperFee
(
nil
)
if
err
!=
nil
{
return
""
,
err
}
fee
,
err
:=
tx
.
GetRealFee
(
proper
.
ProperFee
)
if
err
!=
nil
{
return
""
,
err
}
tx
.
Fee
=
fee
}
}
expire
,
err
:=
types
.
ParseExpire
(
unsigned
.
GetExpire
())
expire
,
err
:=
types
.
ParseExpire
(
unsigned
.
GetExpire
())
...
...
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