core: don't reset NEO's registerPrice cache
This commit is contained in:
parent
adec635f0e
commit
c36448f27e
2 changed files with 12 additions and 21 deletions
|
@ -44,8 +44,7 @@ type NeoCache struct {
|
||||||
// gasPerBlock represents the history of generated gas per block.
|
// gasPerBlock represents the history of generated gas per block.
|
||||||
gasPerBlock gasRecord
|
gasPerBlock gasRecord
|
||||||
|
|
||||||
registerPrice int64
|
registerPrice int64
|
||||||
registerPriceChanged bool
|
|
||||||
|
|
||||||
votesChanged bool
|
votesChanged bool
|
||||||
nextValidators keys.PublicKeys
|
nextValidators keys.PublicKeys
|
||||||
|
@ -126,7 +125,6 @@ func copyNeoCache(src, dst *NeoCache) {
|
||||||
copy(dst.committee, src.committee)
|
copy(dst.committee, src.committee)
|
||||||
dst.committeeHash = src.committeeHash
|
dst.committeeHash = src.committeeHash
|
||||||
|
|
||||||
dst.registerPriceChanged = src.registerPriceChanged
|
|
||||||
dst.registerPrice = src.registerPrice
|
dst.registerPrice = src.registerPrice
|
||||||
|
|
||||||
// Can't omit copying because gasPerBlock is append-only, thus to be able to
|
// Can't omit copying because gasPerBlock is append-only, thus to be able to
|
||||||
|
@ -242,9 +240,8 @@ func (n *NEO) Initialize(ic *interop.Context) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
cache := &NeoCache{
|
cache := &NeoCache{
|
||||||
gasPerVoteCache: make(map[string]big.Int),
|
gasPerVoteCache: make(map[string]big.Int),
|
||||||
votesChanged: true,
|
votesChanged: true,
|
||||||
registerPriceChanged: true,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// We need cache to be present in DAO before the subsequent call to `mint`.
|
// We need cache to be present in DAO before the subsequent call to `mint`.
|
||||||
|
@ -275,7 +272,6 @@ func (n *NEO) Initialize(ic *interop.Context) error {
|
||||||
|
|
||||||
setIntWithKey(n.ID, ic.DAO, []byte{prefixRegisterPrice}, DefaultRegisterPrice)
|
setIntWithKey(n.ID, ic.DAO, []byte{prefixRegisterPrice}, DefaultRegisterPrice)
|
||||||
cache.registerPrice = int64(DefaultRegisterPrice)
|
cache.registerPrice = int64(DefaultRegisterPrice)
|
||||||
cache.registerPriceChanged = false
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -285,9 +281,8 @@ func (n *NEO) Initialize(ic *interop.Context) error {
|
||||||
// called only when deploying native contracts.
|
// called only when deploying native contracts.
|
||||||
func (n *NEO) InitializeCache(bc interop.Ledger, d *dao.Simple) error {
|
func (n *NEO) InitializeCache(bc interop.Ledger, d *dao.Simple) error {
|
||||||
cache := &NeoCache{
|
cache := &NeoCache{
|
||||||
gasPerVoteCache: make(map[string]big.Int),
|
gasPerVoteCache: make(map[string]big.Int),
|
||||||
votesChanged: true,
|
votesChanged: true,
|
||||||
registerPriceChanged: true,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var committee = keysWithVotes{}
|
var committee = keysWithVotes{}
|
||||||
|
@ -300,6 +295,7 @@ func (n *NEO) InitializeCache(bc interop.Ledger, d *dao.Simple) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
cache.gasPerBlock = n.getSortedGASRecordFromDAO(d)
|
cache.gasPerBlock = n.getSortedGASRecordFromDAO(d)
|
||||||
|
cache.registerPrice = getIntWithKey(n.ID, d, []byte{prefixRegisterPrice})
|
||||||
|
|
||||||
d.Store.SetCache(n.ID, cache)
|
d.Store.SetCache(n.ID, cache)
|
||||||
return nil
|
return nil
|
||||||
|
@ -415,12 +411,6 @@ func (n *NEO) PostPersist(ic *interop.Context) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if cache.registerPriceChanged {
|
|
||||||
p := getIntWithKey(n.ID, ic.DAO, []byte{prefixRegisterPrice})
|
|
||||||
cache.registerPrice = p
|
|
||||||
cache.registerPriceChanged = false
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -599,10 +589,7 @@ func (n *NEO) getRegisterPrice(ic *interop.Context, _ []stackitem.Item) stackite
|
||||||
|
|
||||||
func (n *NEO) getRegisterPriceInternal(d *dao.Simple) int64 {
|
func (n *NEO) getRegisterPriceInternal(d *dao.Simple) int64 {
|
||||||
cache := d.Store.GetROCache(n.ID).(*NeoCache)
|
cache := d.Store.GetROCache(n.ID).(*NeoCache)
|
||||||
if !cache.registerPriceChanged {
|
return cache.registerPrice
|
||||||
return cache.registerPrice
|
|
||||||
}
|
|
||||||
return getIntWithKey(n.ID, d, []byte{prefixRegisterPrice})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *NEO) setRegisterPrice(ic *interop.Context, args []stackitem.Item) stackitem.Item {
|
func (n *NEO) setRegisterPrice(ic *interop.Context, args []stackitem.Item) stackitem.Item {
|
||||||
|
@ -616,7 +603,7 @@ func (n *NEO) setRegisterPrice(ic *interop.Context, args []stackitem.Item) stack
|
||||||
|
|
||||||
setIntWithKey(n.ID, ic.DAO, []byte{prefixRegisterPrice}, price.Int64())
|
setIntWithKey(n.ID, ic.DAO, []byte{prefixRegisterPrice}, price.Int64())
|
||||||
cache := ic.DAO.Store.GetRWCache(n.ID).(*NeoCache)
|
cache := ic.DAO.Store.GetRWCache(n.ID).(*NeoCache)
|
||||||
cache.registerPriceChanged = true
|
cache.registerPrice = price.Int64()
|
||||||
return stackitem.Null{}
|
return stackitem.Null{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,6 +50,10 @@ func TestNEO_RegisterPrice(t *testing.T) {
|
||||||
testGetSet(t, newNeoCommitteeClient(t, 100_0000_0000), "RegisterPrice", native.DefaultRegisterPrice, 1, math.MaxInt64)
|
testGetSet(t, newNeoCommitteeClient(t, 100_0000_0000), "RegisterPrice", native.DefaultRegisterPrice, 1, math.MaxInt64)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestNEO_RegisterPriceCache(t *testing.T) {
|
||||||
|
testGetSetCache(t, newNeoCommitteeClient(t, 100_0000_0000), "RegisterPrice", native.DefaultRegisterPrice)
|
||||||
|
}
|
||||||
|
|
||||||
func TestNEO_Vote(t *testing.T) {
|
func TestNEO_Vote(t *testing.T) {
|
||||||
neoCommitteeInvoker := newNeoCommitteeClient(t, 100_0000_0000)
|
neoCommitteeInvoker := newNeoCommitteeClient(t, 100_0000_0000)
|
||||||
neoValidatorsInvoker := neoCommitteeInvoker.WithSigners(neoCommitteeInvoker.Validator)
|
neoValidatorsInvoker := neoCommitteeInvoker.WithSigners(neoCommitteeInvoker.Validator)
|
||||||
|
|
Loading…
Reference in a new issue