Merge pull request #2186 from nspcc-dev/voter-optimizations
NEO voter optimizations
This commit is contained in:
commit
e2a93f3e41
2 changed files with 15 additions and 12 deletions
|
@ -904,6 +904,8 @@ func (bc *Blockchain) GetStateSyncModule() blockchainer.StateSync {
|
||||||
func (bc *Blockchain) storeBlock(block *block.Block, txpool *mempool.Pool) error {
|
func (bc *Blockchain) storeBlock(block *block.Block, txpool *mempool.Pool) error {
|
||||||
var (
|
var (
|
||||||
cache = bc.dao.GetWrapped()
|
cache = bc.dao.GetWrapped()
|
||||||
|
blockCache = bc.dao.GetWrapped()
|
||||||
|
aerCache = bc.dao.GetWrapped()
|
||||||
appExecResults = make([]*state.AppExecResult, 0, 2+len(block.Transactions))
|
appExecResults = make([]*state.AppExecResult, 0, 2+len(block.Transactions))
|
||||||
aerchan = make(chan *state.AppExecResult, len(block.Transactions)/8) // Tested 8 and 4 with no practical difference, but feel free to test more and tune.
|
aerchan = make(chan *state.AppExecResult, len(block.Transactions)/8) // Tested 8 and 4 with no practical difference, but feel free to test more and tune.
|
||||||
aerdone = make(chan error)
|
aerdone = make(chan error)
|
||||||
|
@ -911,7 +913,7 @@ func (bc *Blockchain) storeBlock(block *block.Block, txpool *mempool.Pool) error
|
||||||
)
|
)
|
||||||
go func() {
|
go func() {
|
||||||
var (
|
var (
|
||||||
kvcache = cache.GetWrapped()
|
kvcache = blockCache
|
||||||
writeBuf = io.NewBufBinWriter()
|
writeBuf = io.NewBufBinWriter()
|
||||||
)
|
)
|
||||||
if err := kvcache.StoreAsBlock(block, writeBuf); err != nil {
|
if err := kvcache.StoreAsBlock(block, writeBuf); err != nil {
|
||||||
|
@ -960,15 +962,11 @@ func (bc *Blockchain) storeBlock(block *block.Block, txpool *mempool.Pool) error
|
||||||
writeBuf.Reset()
|
writeBuf.Reset()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_, err := kvcache.Persist()
|
|
||||||
if err != nil {
|
|
||||||
blockdone <- err
|
|
||||||
}
|
|
||||||
close(blockdone)
|
close(blockdone)
|
||||||
}()
|
}()
|
||||||
go func() {
|
go func() {
|
||||||
var (
|
var (
|
||||||
kvcache = cache.GetWrapped()
|
kvcache = aerCache
|
||||||
writeBuf = io.NewBufBinWriter()
|
writeBuf = io.NewBufBinWriter()
|
||||||
err error
|
err error
|
||||||
appendBlock bool
|
appendBlock bool
|
||||||
|
@ -1010,11 +1008,6 @@ func (bc *Blockchain) storeBlock(block *block.Block, txpool *mempool.Pool) error
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = kvcache.Persist()
|
|
||||||
if err != nil {
|
|
||||||
aerdone <- err
|
|
||||||
}
|
|
||||||
close(aerdone)
|
close(aerdone)
|
||||||
}()
|
}()
|
||||||
aer, err := bc.runPersist(bc.contracts.GetPersistScript(), block, cache, trigger.OnPersist)
|
aer, err := bc.runPersist(bc.contracts.GetPersistScript(), block, cache, trigger.OnPersist)
|
||||||
|
@ -1129,6 +1122,16 @@ func (bc *Blockchain) storeBlock(block *block.Block, txpool *mempool.Pool) error
|
||||||
}
|
}
|
||||||
|
|
||||||
bc.lock.Lock()
|
bc.lock.Lock()
|
||||||
|
_, err = blockCache.Persist()
|
||||||
|
if err != nil {
|
||||||
|
bc.lock.Unlock()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = aerCache.Persist()
|
||||||
|
if err != nil {
|
||||||
|
bc.lock.Unlock()
|
||||||
|
return err
|
||||||
|
}
|
||||||
_, err = cache.Persist()
|
_, err = cache.Persist()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
bc.lock.Unlock()
|
bc.lock.Unlock()
|
||||||
|
|
|
@ -434,7 +434,7 @@ func (n *NEO) balanceFromBytes(si *state.StorageItem) (*big.Int, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *NEO) distributeGas(ic *interop.Context, h util.Uint160, acc *state.NEOBalance) error {
|
func (n *NEO) distributeGas(ic *interop.Context, h util.Uint160, acc *state.NEOBalance) error {
|
||||||
if ic.Block == nil || ic.Block.Index == 0 {
|
if ic.Block == nil || ic.Block.Index == 0 || ic.Block.Index == acc.BalanceHeight {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
gen, err := n.calculateBonus(ic.DAO, acc.VoteTo, &acc.Balance, acc.BalanceHeight, ic.Block.Index)
|
gen, err := n.calculateBonus(ic.DAO, acc.VoteTo, &acc.Balance, acc.BalanceHeight, ic.Block.Index)
|
||||||
|
|
Loading…
Reference in a new issue