Skip to content

Commit

Permalink
unknown reason cause ticket's storage broken with illegal key
Browse files Browse the repository at this point in the history
I'm not sure if add lock can solve this problem.
It's hard to reproduce the bug,
may be need more chain split and call fsn.allTickets() in api frequently
  • Loading branch information
zongyuan committed Jun 12, 2019
1 parent dbc0028 commit ed23b49
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ type StateDB struct {
validRevisions []revision
nextRevisionId int

lock sync.Mutex
lock sync.Mutex
rwlock sync.RWMutex
}

// Create a new state from a given trie.
Expand Down Expand Up @@ -951,6 +952,9 @@ func (db *StateDB) UpdateAsset(asset common.Asset) error {
func (db *StateDB) setTicketState(key, value common.Hash) {
stateObject := db.GetOrNewStateObject(common.TicketKeyAddress)
if stateObject != nil {
db.rwlock.Lock()
defer db.rwlock.Unlock()

stateObject.SetState(db.db, key, value)
}
}
Expand All @@ -965,6 +969,9 @@ func (db *StateDB) IsTicketExist(id common.Hash) bool {
func (db *StateDB) GetTicket(id common.Hash) (*common.Ticket, error) {
stateObject := db.getStateObject(common.TicketKeyAddress)
if stateObject != nil && id != (common.Hash{}) {
db.rwlock.RLock()
defer db.rwlock.RUnlock()

value := stateObject.GetState(db.db, id)
ticket, err := common.ParseTicket(id, value)
if err == nil {
Expand All @@ -976,6 +983,9 @@ func (db *StateDB) GetTicket(id common.Hash) (*common.Ticket, error) {

// AllTickets wacom
func (db *StateDB) AllTickets() (common.TicketSlice, error) {
db.rwlock.RLock()
defer db.rwlock.RUnlock()

stateObject := db.getStateObject(common.TicketKeyAddress)
if stateObject == nil {
return nil, nil
Expand Down

0 comments on commit ed23b49

Please sign in to comment.