func (s *Sync) Commit(sdb db.IStore) error {
	s.Lock()
	defer s.Unlock()
	for key, value := range s.membatch {
		err := sdb.BatchPut(db.TrieNodeKey(key.ToArray()), value)
		if err != nil {
			return err
		}
	}
	s.membatch = make(map[common.Uint256][]byte)
	return nil
}
Commit flushes the data stored in the internal membatch out to persistent
storage, returning any occurred error.
package trie
import (
	"sync"
	"github.com/nknorg/nkn/v2/chain/db"
	"github.com/nknorg/nkn/v2/util/log"
	"github.com/nknorg/nkn/v2/common"
)
type SyncPath []byte
type request struct {
	path []byte          
	data []byte          
	hash common.Uint256  
}
type SyncResult struct {
	Hash common.Uint256  
	Data []byte          
}
type Sync struct {
	sync.RWMutex
	membatch map[common.Uint256][]byte    
	nodeReqs map[common.Uint256]*request  
	queue    *common.PriorityQueue        
	DataAvailable chan struct{}  
}
func NewSync(root common.Uint256) *Sync {
	ts := &Sync{
		queue:         common.NewPrque(),
		membatch:      make(map[common.Uint256][]byte),
		nodeReqs:      make(map[common.Uint256]*request),
		DataAvailable: make(chan struct{}, 1),
	}
	ts.AddSubTrie(root, nil)
	return ts
}
func (s *Sync) AddSubTrie(root common.Uint256, path []byte) {
	s.Lock()
	defer s.Unlock()
	req := &request{
		path: path,
		hash: root,
	}
	s.schedule(req)
}
func (s *Sync) Pending() int {
	s.RLock()
	defer s.RUnlock()
	return len(s.nodeReqs)
}
func (s *Sync) Pop(max int) ([]common.Uint256, []int64) {
	s.Lock()
	defer s.Unlock()
	var (
		nodeHashes []common.Uint256
		prios      []int64
	)
	for !s.queue.Empty() && (max == 0 || len(nodeHashes) < max) {
		item, p := s.queue.Pop()
		hash := item.(common.Uint256)
		nodeHashes = append(nodeHashes, hash)
		prios = append(prios, p)
	}
	return nodeHashes, prios
}
func (s *Sync) Push(hashes []common.Uint256, prio int64) {
	s.Lock()
	defer s.Unlock()
	for _, h := range hashes {
		s.queue.Push(h, prio)
	}
	select {
	case s.DataAvailable <- struct{}{}:
	default:
	}
}