Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG:getStateRoot performance issues #356

Merged
merged 1 commit into from
Mar 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions consensus/forks/meerevmfork.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,10 @@ func IsMeerEVMUTXOHeight(mainHeight int64) bool {
}
return mainHeight >= MeerEVMUTXOUnlockMainHeight
}

func IsBeforeMeerEVMForkHeight(mainHeight int64) bool {
if params.ActiveNetParams.Net != protocol.MainNet {
return false
}
return mainHeight < MeerEVMForkMainHeight
}
2 changes: 2 additions & 0 deletions core/blockchain/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,8 @@ func (api *PublicBlockAPI) GetStateRoot(order int64, verbose *bool) (interface{}
} else {
if order > mainOrder {
return nil, fmt.Errorf("Order is too big")
} else if order < 0 {
return nil, fmt.Errorf("Order is too small")
}
}
vb := false
Expand Down
9 changes: 6 additions & 3 deletions core/blockchain/blockindex.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,14 @@ func (b *BlockChain) GetMeerBlock(order uint) (interface{}, error) {
}
number := uint64(0)
for i := uint(order); i > 0; i-- {
bh := b.bd.GetBlockHashByOrder(i)
if bh == nil {
ib := b.bd.GetBlockByOrder(i)
if ib == nil {
return nil, fmt.Errorf("No meer block number:%d", i)
}
num := b.VMService().GetBlockID(bh)
if forks.IsBeforeMeerEVMForkHeight(int64(ib.GetHeight())) {
break
}
num := b.VMService().GetBlockID(ib.GetHash())
if num != 0 {
number = num
break
Expand Down