log "github.com/sirupsen/logrus"
"github.com/vapor/consensus"
- "github.com/vapor/consensus/difficulty"
"github.com/vapor/errors"
"github.com/vapor/protocol/bc"
"github.com/vapor/protocol/bc/types"
)
func checkBlockTime(b *bc.Block, parent *state.BlockNode) error {
- if b.Timestamp > uint64(time.Now().Unix())+consensus.MaxTimeOffsetSeconds {
+ if b.Timestamp > uint64(time.Now().UnixNano()/int64(time.Millisecond))+consensus.MaxTimeOffsetMs {
return errBadTimestamp
}
return errors.Wrap(ErrWrongCoinbaseTransaction, "have more than 1 output")
}
- output, err := tx.Output(*tx.TxHeader.ResultIds[0])
- if err != nil {
- return err
+ var SourceAmount uint64
+ switch output := tx.Entries[*tx.TxHeader.ResultIds[0]].(type) {
+ case *bc.IntraChainOutput:
+ SourceAmount = output.Source.Value.Amount
+ case *bc.VoteOutput:
+ SourceAmount = output.Source.Value.Amount
+ default:
+ return errors.Wrapf(bc.ErrEntryType, "entry %x has unexpected type %T", tx.TxHeader.ResultIds[0].Bytes(), output)
}
- if output.Source.Value.Amount != amount {
+ if SourceAmount != amount {
return errors.Wrap(ErrWrongCoinbaseTransaction, "dismatch output amount")
}
return nil
if b.Height != parent.Height+1 {
return errors.WithDetailf(errMisorderedBlockHeight, "previous block height %d, current block height %d", parent.Height, b.Height)
}
- if b.Bits != parent.CalcNextBits() {
- return errBadBits
- }
if parent.Hash != *b.PreviousBlockId {
return errors.WithDetailf(errMismatchedBlock, "previous block ID %x, current block wants %x", parent.Hash.Bytes(), b.PreviousBlockId.Bytes())
}
- if err := checkBlockTime(b, parent); err != nil {
- return err
- }
- if !difficulty.CheckProofOfWork(&b.ID, parent.CalcNextSeed(), b.BlockHeader.Bits) {
- return errWorkProof
- }
- return nil
+
+ return checkBlockTime(b, parent)
}
// ValidateBlock validates a block and the transactions within.
return errors.Wrap(err, "computing transaction id merkle root")
}
if txMerkleRoot != *b.TransactionsRoot {
- return errors.WithDetailf(errMismatchedMerkleRoot, "transaction id merkle root")
+ return errors.WithDetailf(errMismatchedMerkleRoot, "transaction id merkle root. compute: %v, given: %v", txMerkleRoot, *b.TransactionsRoot)
}
txStatusHash, err := types.TxStatusMerkleRoot(b.TransactionStatus.VerifyStatus)