func (sm *ShardStateManager) Add(block *primitives.ShardBlock) (*chainhash.Hash, error) {
	sm.stateLock.Lock()
	defer sm.stateLock.Unlock()

	blockHash, _ := ssz.HashTreeRoot(block)
	if sm.has(blockHash) {
		// we already got this block
		return nil, nil
	}

	logrus.WithField("block hash", chainhash.Hash(blockHash)).WithField("shard", sm.shardInfo.ShardID).Debug("add block action")

	previousState, found := sm.stateMap[block.Header.PreviousBlockHash]
	if !found {
		return nil, fmt.Errorf("could not find parent block with hash: %s", block.Header.PreviousBlockHash)
	}

	newCache, err := csmt.NewTreeMemoryCache(previousState.db)
	if err != nil {
		return nil, err
	}

	newCacheTree := csmt.NewTree(newCache)
	err = newCacheTree.Update(func(access csmt.TreeTransactionAccess) error {
		return executeBlockTransactions(access, *block, sm.shardInfo)
	})
	if err != nil {
		return nil, err
	}

	sm.stateMap[blockHash] = &stateInfo{
		db:     newCache,
		parent: previousState,
		slot:   block.Header.Slot,
		hash: blockHash,
	}

	return newCache.Hash()
}
// Add adds a block to the state map.
Add adds a block to the state map.
// Add adds a block to the state map .
func (sm *ShardStateManager) Add(block *primitives.ShardBlock) (*chainhash.Hash, error) {
	sm.stateLock.Lock()
	defer sm.stateLock.Unlock()
	blockHash, _ := ssz.HashTreeRoot(block)
	if sm.has(blockHash) {
		return nil, nil
	}
	logrus.WithField("block hash", chainhash.Hash(blockHash)).WithField("shard", sm.shardInfo.ShardID).Debug("add block action")
	previousState, found := sm.stateMap[block.Header.PreviousBlockHash]
	if !found {
		return nil, fmt.Errorf("could not find parent block with hash: %s", block.Header.PreviousBlockHash)
	}
	newCache, err := csmt.NewTreeMemoryCache(previousState.db)
	if err != nil {
		return nil, err
	}
	newCacheTree := csmt.NewTree(newCache)
	err = newCacheTree.Update(func(access csmt.TreeTransactionAccess) error {
		return executeBlockTransactions(access, *block, sm.shardInfo)
	})
	if err != nil {
		return nil, err
	}
	sm.stateMap[blockHash] = &stateInfo{
		db:     newCache,
		parent: previousState,
		slot:   block.Header.Slot,
		hash: blockHash,
	}
	return newCache.Hash()
}
func ( sm * ShardStateManager ) Add ( block * primitives . ShardBlock ) ( * chainhash . Hash , error ) { sm . stateLock . Lock ( ) defer sm . stateLock . Unlock ( ) blockHash , _ := ssz . HashTreeRoot ( block ) if sm . has ( blockHash ) { return nil , nil } logrus . WithField ( " " , chainhash . Hash ( blockHash ) ) . WithField ( " " , sm . shardInfo . ShardID ) . Debug ( " " ) previousState , found := sm . stateMap [ block . Header . PreviousBlockHash ] if ! found { return nil , fmt . Errorf ( " " , block . Header . PreviousBlockHash ) } newCache , err := csmt . NewTreeMemoryCache ( previousState . db ) if err != nil { return nil , err } newCacheTree := csmt . NewTree ( newCache ) err = newCacheTree . Update ( func ( access csmt . TreeTransactionAccess ) error { return executeBlockTransactions ( access , * block , sm . shardInfo ) } ) if err != nil { return nil , err } sm . stateMap [ blockHash ] = & stateInfo { db : newCache , parent : previousState , slot : block . Header . Slot , hash : blockHash , } return newCache . Hash ( ) }
Add adds a block to the state map.
Add adds a block to the state map .
// we already got this block