func (sm *ShardManager) ProcessBlock(block primitives.ShardBlock) error {
	h, _ := ssz.HashTreeRoot(block)

	logrus.WithFields(logrus.Fields{
		"slot":         block.Header.Slot,
		"hash":         chainhash.Hash(h),
		"shard":        sm.ShardID,
		"transactions": len(block.Body.Transactions),
	}).Debug("processing block")

	// first, let's make sure we have the parent block
	hasParent := sm.Index.HasBlock(block.Header.PreviousBlockHash)
	if !hasParent {
		return fmt.Errorf("missing parent block %s", block.Header.PreviousBlockHash)
	}

	if sm.stateManager.Has(h) {
		return nil
	}

	newStateRoot, err := sm.stateManager.Add(&block)
	if err != nil {
		return err
	}

	if !block.Header.StateRoot.IsEqual(newStateRoot) {
		return fmt.Errorf("expected new state root: %s, but block state root is %s", newStateRoot, block.Header.StateRoot)
	}

	if block.Header.Slot*uint64(sm.Config.SlotDuration)+sm.InitializationParameters.GenesisTime > uint64(utils.Now().Unix()) {
		return fmt.Errorf("shard block submitted too soon")
	}

	// TODO: check shard chain proposer

	blockWithNoSignature := block.Copy()
	blockWithNoSignature.Header.Signature = bls.EmptySignature.Serialize()

	// blockHashNoSignature, err := ssz.HashTreeRoot(blockWithNoSignature)
	// if err != nil {
	// 	return err
	// }

	// var pubkeySerialized [96]byte
	// copy(pubkeySerialized[:], proposer.ProposerPublicKey)

	// proposerPublicKey, err := bls.DeserializePublicKey(pubkeySerialized)
	// if err != nil {
	// 	return err
	// }

	// blockSig, err := bls.DeserializeSignature(block.Header.Signature)
	// if err != nil {
	// 	return err
	// }

	// valid, err := bls.VerifySig(proposerPublicKey, blockHashNoSignature[:], blockSig, bls.DomainShardProposal)
	// if err != nil {
	// 	return err
	// }

	// if !valid {
	// 	return errors.New("block signature was not valid")
	// }

	node, err := sm.Index.AddToIndex(block)
	if err != nil {
		return err
	}

	if err := sm.BlockDB.SetBlock(&block); err != nil {
		return err
	}

	// TODO: improve fork choice here
	tipNode, err := sm.Chain.Tip()
	if err != nil {
		return err
	}

	newTip := false
	if node.Height > tipNode.Height || (node.Height == tipNode.Height && node.Slot > tipNode.Slot) {
		sm.Chain.SetTip(node)
		if err := sm.stateManager.SetTip(node.BlockHash); err != nil {
			return err
		}

		newTip = true
	}

	sm.notifeesLock.Lock()
	for _, n := range sm.notifees {
		n.AddBlock(&block, newTip)
	}
	sm.notifeesLock.Unlock()

	return nil
}
// ProcessBlock submits a block to the chain for processing.
ProcessBlock submits a block to the chain for processing.
// ProcessBlock submits a block to the chain for processing .
func (sm *ShardManager) ProcessBlock(block primitives.ShardBlock) error {
	h, _ := ssz.HashTreeRoot(block)
	logrus.WithFields(logrus.Fields{
		"slot":         block.Header.Slot,
		"hash":         chainhash.Hash(h),
		"shard":        sm.ShardID,
		"transactions": len(block.Body.Transactions),
	}).Debug("processing block")
	hasParent := sm.Index.HasBlock(block.Header.PreviousBlockHash)
	if !hasParent {
		return fmt.Errorf("missing parent block %s", block.Header.PreviousBlockHash)
	}
	if sm.stateManager.Has(h) {
		return nil
	}
	newStateRoot, err := sm.stateManager.Add(&block)
	if err != nil {
		return err
	}
	if !block.Header.StateRoot.IsEqual(newStateRoot) {
		return fmt.Errorf("expected new state root: %s, but block state root is %s", newStateRoot, block.Header.StateRoot)
	}
	if block.Header.Slot*uint64(sm.Config.SlotDuration)+sm.InitializationParameters.GenesisTime > uint64(utils.Now().Unix()) {
		return fmt.Errorf("shard block submitted too soon")
	}
	blockWithNoSignature := block.Copy()
	blockWithNoSignature.Header.Signature = bls.EmptySignature.Serialize()
	ors.New("block signature was not valid")
	node, err := sm.Index.AddToIndex(block)
	if err != nil {
		return err
	}
	if err := sm.BlockDB.SetBlock(&block); err != nil {
		return err
	}
	tipNode, err := sm.Chain.Tip()
	if err != nil {
		return err
	}
	newTip := false
	if node.Height > tipNode.Height || (node.Height == tipNode.Height && node.Slot > tipNode.Slot) {
		sm.Chain.SetTip(node)
		if err := sm.stateManager.SetTip(node.BlockHash); err != nil {
			return err
		}
		newTip = true
	}
	sm.notifeesLock.Lock()
	for _, n := range sm.notifees {
		n.AddBlock(&block, newTip)
	}
	sm.notifeesLock.Unlock()
	return nil
}
func ( sm * ShardManager ) ProcessBlock ( block primitives . ShardBlock ) error { h , _ := ssz . HashTreeRoot ( block ) logrus . WithFields ( logrus . Fields { " " : block . Header . Slot , " " : chainhash . Hash ( h ) , " " : sm . ShardID , " " : len ( block . Body . Transactions ) , } ) . Debug ( " " ) hasParent := sm . Index . HasBlock ( block . Header . PreviousBlockHash ) if ! hasParent { return fmt . Errorf ( " " , block . Header . PreviousBlockHash ) } if sm . stateManager . Has ( h ) { return nil } newStateRoot , err := sm . stateManager . Add ( & block ) if err != nil { return err } if ! block . Header . StateRoot . IsEqual ( newStateRoot ) { return fmt . Errorf ( " " , newStateRoot , block . Header . StateRoot ) } if block . Header . Slot * uint64 ( sm . Config . SlotDuration ) + sm . InitializationParameters . GenesisTime > uint64 ( utils . Now ( ) . Unix ( ) ) { return fmt . Errorf ( " " ) } blockWithNoSignature := block . Copy ( ) blockWithNoSignature . Header . Signature = bls . EmptySignature . Serialize ( ) node , err := sm . Index . AddToIndex ( block ) if err != nil { return err } if err := sm . BlockDB . SetBlock ( & block ) ; err != nil { return err } tipNode , err := sm . Chain . Tip ( ) if err != nil { return err } newTip := false if node . Height > tipNode . Height || ( node . Height == tipNode . Height && node . Slot > tipNode . Slot ) { sm . Chain . SetTip ( node ) if err := sm . stateManager . SetTip ( node . BlockHash ) ; err != nil { return err } newTip = true } sm . notifeesLock . Lock ( ) for _ , n := range sm . notifees { n . AddBlock ( & block , newTip ) } sm . notifeesLock . Unlock ( ) return nil }
ProcessBlock submits a block to the chain for processing.
ProcessBlock submits a block to the chain for processing .
// first, let's make sure we have the parent block // TODO: check shard chain proposer // blockHashNoSignature, err := ssz.HashTreeRoot(blockWithNoSignature) // if err != nil { // 	return err // } // var pubkeySerialized [96]byte // copy(pubkeySerialized[:], proposer.ProposerPublicKey) // proposerPublicKey, err := bls.DeserializePublicKey(pubkeySerialized) // if err != nil { // 	return err // } // blockSig, err := bls.DeserializeSignature(block.Header.Signature) // if err != nil { // 	return err // } // valid, err := bls.VerifySig(proposerPublicKey, blockHashNoSignature[:], blockSig, bls.DomainShardProposal) // if err != nil { // 	return err // } // if !valid { // 	return errors.New("block signature was not valid") // } // TODO: improve fork choice here