func (s *ShardMempool) AcceptAction(action *pb.ShardChainAction) error {
	// We have 3 types of actions:
	// 1. AddBlockAction - adds a block and executes it, adding the result to the state map
	// 2. FinalizeBlockAction - finalizes a block, deletes all states before it, and commits changes to disk
	// 3. UpdateTip - updates the current tip to a certain block hash

	// add block adds a block to the chain
	if action.AddBlockAction != nil {
		blockToAdd, err := primitives.ShardBlockFromProto(action.AddBlockAction.Block)
		if err != nil {
			return err
		}

		if _, err := s.stateManager.Add(blockToAdd); err != nil {
			return err
		}

		s.RemoveTransactionsFromBlock(blockToAdd)
	} else if action.FinalizeBlockAction != nil {
		toFinalizeHash, err := chainhash.NewHash(action.FinalizeBlockAction.Hash)
		if err != nil {
			return err
		}

		if err := s.stateManager.Finalize(*toFinalizeHash, action.FinalizeBlockAction.Slot); err != nil {
			return err
		}
	} else if action.UpdateTip != nil {
		newTipHash, err := chainhash.NewHash(action.UpdateTip.Hash)
		if err != nil {
			return err
		}

		if err := s.stateManager.SetTip(*newTipHash); err != nil {
			return err
		}
	}

	return nil
}
// AcceptAction updates the current state with all of the
AcceptAction updates the current state with all of the
// AcceptAction updates the current state with all of the
func (s *ShardMempool) AcceptAction(action *pb.ShardChainAction) error {
	if action.AddBlockAction != nil {
		blockToAdd, err := primitives.ShardBlockFromProto(action.AddBlockAction.Block)
		if err != nil {
			return err
		}
		if _, err := s.stateManager.Add(blockToAdd); err != nil {
			return err
		}
		s.RemoveTransactionsFromBlock(blockToAdd)
	} else if action.FinalizeBlockAction != nil {
		toFinalizeHash, err := chainhash.NewHash(action.FinalizeBlockAction.Hash)
		if err != nil {
			return err
		}
		if err := s.stateManager.Finalize(*toFinalizeHash, action.FinalizeBlockAction.Slot); err != nil {
			return err
		}
	} else if action.UpdateTip != nil {
		newTipHash, err := chainhash.NewHash(action.UpdateTip.Hash)
		if err != nil {
			return err
		}
		if err := s.stateManager.SetTip(*newTipHash); err != nil {
			return err
		}
	}
	return nil
}
func ( s * ShardMempool ) AcceptAction ( action * pb . ShardChainAction ) error { if action . AddBlockAction != nil { blockToAdd , err := primitives . ShardBlockFromProto ( action . AddBlockAction . Block ) if err != nil { return err } if _ , err := s . stateManager . Add ( blockToAdd ) ; err != nil { return err } s . RemoveTransactionsFromBlock ( blockToAdd ) } else if action . FinalizeBlockAction != nil { toFinalizeHash , err := chainhash . NewHash ( action . FinalizeBlockAction . Hash ) if err != nil { return err } if err := s . stateManager . Finalize ( * toFinalizeHash , action . FinalizeBlockAction . Slot ) ; err != nil { return err } } else if action . UpdateTip != nil { newTipHash , err := chainhash . NewHash ( action . UpdateTip . Hash ) if err != nil { return err } if err := s . stateManager . SetTip ( * newTipHash ) ; err != nil { return err } } return nil }
AcceptAction updates the current state with all of the
AcceptAction updates the current state with all of the
// We have 3 types of actions: // 1. AddBlockAction - adds a block and executes it, adding the result to the state map // 2. FinalizeBlockAction - finalizes a block, deletes all states before it, and commits changes to disk // 3. UpdateTip - updates the current tip to a certain block hash // add block adds a block to the chain