// filterInvalidVotes takes a slice of (*finalizationVote)'s and filters away
// ones that are invalid with respect to the current nodes state.
filterInvalidVotes takes a slice of (*finalizationVote)'s and filters away
ones that are invalid with respect to the current nodes state.
// filterInvalidVotes takes a slice of ( * finalizationVote ) ' s and filters away // ones that are invalid with respect to the current nodes state .
func (l *Ledger) filterInvalidVotes(current *Block, votes []Vote) {
ValidateVotes:
	for _, vote := range votes {
		vote := vote.(*finalizationVote)
		if vote.block == nil {
			continue ValidateVotes
		}
		if _, exists := l.queryBlockValidCache[vote.block.ID]; exists {
			continue ValidateVotes
		}
		if vote.block.Index != current.Index+1 {
			dbg("got block not suited for current height", vote.block.Index, current.Index+1)
			vote.block = nil
			continue ValidateVotes
		}
		if l.transactions.BatchMarkMissing(vote.block.Transactions...) {
			dbg("we're missing some transactions from block",
				hex.EncodeToString(vote.block.ID[:]),
				"made for height",
				vote.block.Index,
				"while we're finalizing",
				current.Index+1,
			)
			vote.block = nil
			continue ValidateVotes
		}
		transactions, _ := l.transactions.BatchFind(vote.block.Transactions)
		for i := range transactions {
			if vote.block.Index >= transactions[i].Block+uint64(conf.GetPruningLimit()) {
				vote.block = nil
				continue ValidateVotes
			}
			if i > 0 { 
				if bytes.Compare(transactions[i-1].ComputeIndex(current.ID), transactions[i].ComputeIndex(current.ID)) >= 0 {
					vote.block = nil
					continue ValidateVotes
				}
			}
		}
		results, err := l.collapseTransactions(vote.block.Index, current, vote.block.Transactions, false)
		if err != nil {
			dbg("failed to collapse for block",
				hex.EncodeToString(vote.block.ID[:]),
				"made for height",
				vote.block.Index,
				"while we're finalizing",
				current.Index+1,
				err,
			)
			logger := log.Node()
			logger.Error().
				Err(err).
				Msg("error collapsing transactions during query")
			vote.block = nil
			continue ValidateVotes
		}
		if results.snapshot.Checksum() != vote.block.Merkle {
			c := results.snapshot.Checksum()
			dbg("got bad merkle root for block",
				hex.EncodeToString(vote.block.ID[:]),
				"made for height",
				vote.block.Index,
				"while we're finalizing",
				current.Index+1,
				"the root is",
				hex.EncodeToString(vote.block.Merkle[:]),
				"but computed",
				hex.EncodeToString(c[:]),
			)
			vote.block = nil
			continue ValidateVotes
		}
		l.queryBlockValidCache[vote.block.ID] = struct{}{}
	}
}
func ( l * Ledger ) filterInvalidVotes ( current * Block , votes [ ] Vote ) { ValidateVotes : for _ , vote := range votes { vote := vote . ( * finalizationVote ) if vote . block == nil { continue ValidateVotes } if _ , exists := l . queryBlockValidCache [ vote . block . ID ] ; exists { continue ValidateVotes } if vote . block . Index != current . Index + 1 { dbg ( " " , vote . block . Index , current . Index + 1 ) vote . block = nil continue ValidateVotes } if l . transactions . BatchMarkMissing ( vote . block . Transactions ... ) { dbg ( " " , hex . EncodeToString ( vote . block . ID [ : ] ) , " " , vote . block . Index , " " , current . Index + 1 , ) vote . block = nil continue ValidateVotes } transactions , _ := l . transactions . BatchFind ( vote . block . Transactions ) for i := range transactions { if vote . block . Index >= transactions [ i ] . Block + uint64 ( conf . GetPruningLimit ( ) ) { vote . block = nil continue ValidateVotes } if i > 0 { if bytes . Compare ( transactions [ i - 1 ] . ComputeIndex ( current . ID ) , transactions [ i ] . ComputeIndex ( current . ID ) ) >= 0 { vote . block = nil continue ValidateVotes } } } results , err := l . collapseTransactions ( vote . block . Index , current , vote . block . Transactions , false ) if err != nil { dbg ( " " , hex . EncodeToString ( vote . block . ID [ : ] ) , " " , vote . block . Index , " " , current . Index + 1 , err , ) logger := log . Node ( ) logger . Error ( ) . Err ( err ) . Msg ( " " ) vote . block = nil continue ValidateVotes } if results . snapshot . Checksum ( ) != vote . block . Merkle { c := results . snapshot . Checksum ( ) dbg ( " " , hex . EncodeToString ( vote . block . ID [ : ] ) , " " , vote . block . Index , " " , current . Index + 1 , " " , hex . EncodeToString ( vote . block . Merkle [ : ] ) , " " , hex . EncodeToString ( c [ : ] ) , ) vote . block = nil continue ValidateVotes } l . queryBlockValidCache [ vote . block . ID ] = struct { } { } } }
filterInvalidVotes takes a slice of (*finalizationVote)'s and filters away
ones that are invalid with respect to the current nodes state.
filterInvalidVotes takes a slice of ( * finalizationVote ) ' s and filters away ones that are invalid with respect to the current nodes state .
// Ignore nil block proposals. // Skip validating the block if it has already been validated before. // Ignore block proposals at an unexpected height. // Ignore block proposals containing transactions which our node has not // locally archived, and mark them as missing. // Validate the height recorded on transactions inside the block proposal. // Filter away block proposals with transaction IDs that are not properly sorted. // Derive the Merkle root of the block by cloning the current ledger state, and applying // all transactions in the block into the ledger state. // Validate the Merkle root recorded on the block with the resultant Merkle root we got // from applying all transactions in the block.