OSDN Git Service

add broadcast block signature (#139)
[bytom/vapor.git] / protocol / validation / block.go
index 827750d..630a87d 100644 (file)
@@ -26,13 +26,14 @@ var (
 )
 
 func checkBlockTime(b *bc.Block, parent *state.BlockNode) error {
-       if b.Timestamp > uint64(time.Now().Unix())+consensus.MaxTimeOffsetSeconds {
+       now := uint64(time.Now().UnixNano() / 1e6)
+       if b.Timestamp < (parent.Timestamp + consensus.BlockTimeInterval) {
                return errBadTimestamp
        }
-
-       if b.Timestamp <= parent.CalcPastMedianTime() {
+       if b.Timestamp > (now + consensus.MaxTimeOffsetMs) {
                return errBadTimestamp
        }
+
        return nil
 }
 
@@ -46,12 +47,17 @@ func checkCoinbaseAmount(b *bc.Block, amount uint64) error {
                return errors.Wrap(ErrWrongCoinbaseTransaction, "have more than 1 output")
        }
 
-       output, err := tx.IntraChainOutput(*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