OSDN Git Service

remove the timerange check
authorColt <colt@ColtdeMBP.lan>
Fri, 18 Aug 2017 03:15:58 +0000 (11:15 +0800)
committerColt <colt@ColtdeMBP.lan>
Fri, 18 Aug 2017 03:15:58 +0000 (11:15 +0800)
protocol/bc/bc.pb.go
protocol/bc/bc.proto
protocol/bc/legacy/map.go
protocol/bc/nonce.go
protocol/validation/validation.go
protocol/validation/validation_test.go

index 3cbfba9..e0515cc 100644 (file)
@@ -436,10 +436,9 @@ func (m *Mux) GetWitnessArguments() [][]byte {
 
 type Nonce struct {
        Program           *Program `protobuf:"bytes,1,opt,name=program" json:"program,omitempty"`
-       TimeRangeId       *Hash    `protobuf:"bytes,2,opt,name=time_range_id,json=timeRangeId" json:"time_range_id,omitempty"`
-       ExtHash           *Hash    `protobuf:"bytes,3,opt,name=ext_hash,json=extHash" json:"ext_hash,omitempty"`
-       WitnessArguments  [][]byte `protobuf:"bytes,4,rep,name=witness_arguments,json=witnessArguments,proto3" json:"witness_arguments,omitempty"`
-       WitnessAnchoredId *Hash    `protobuf:"bytes,5,opt,name=witness_anchored_id,json=witnessAnchoredId" json:"witness_anchored_id,omitempty"`
+       ExtHash           *Hash    `protobuf:"bytes,2,opt,name=ext_hash,json=extHash" json:"ext_hash,omitempty"`
+       WitnessArguments  [][]byte `protobuf:"bytes,3,rep,name=witness_arguments,json=witnessArguments,proto3" json:"witness_arguments,omitempty"`
+       WitnessAnchoredId *Hash    `protobuf:"bytes,4,opt,name=witness_anchored_id,json=witnessAnchoredId" json:"witness_anchored_id,omitempty"`
 }
 
 func (m *Nonce) Reset()                    { *m = Nonce{} }
@@ -454,13 +453,6 @@ func (m *Nonce) GetProgram() *Program {
        return nil
 }
 
-func (m *Nonce) GetTimeRangeId() *Hash {
-       if m != nil {
-               return m.TimeRangeId
-       }
-       return nil
-}
-
 func (m *Nonce) GetExtHash() *Hash {
        if m != nil {
                return m.ExtHash
index 5ee30ff..81cbbb9 100644 (file)
@@ -79,10 +79,9 @@ message Mux {
 
 message Nonce {
   Program        program             = 1;
-  Hash           time_range_id       = 2;
-  Hash           ext_hash            = 3;
-  repeated bytes witness_arguments   = 4;
-  Hash           witness_anchored_id = 5;
+  Hash           ext_hash            = 2;
+  repeated bytes witness_arguments   = 3;
+  Hash           witness_anchored_id = 4;
 }
 
 message Coinbase {
index 6adc261..d2e105a 100644 (file)
@@ -121,8 +121,6 @@ func mapTx(tx *TxData) (headerID bc.Hash, hdr *bc.TxHeader, entryMap map[bc.Hash
                        )
 
                        if len(oldIss.Nonce) > 0 {
-                               tr := bc.NewTimeRange(tx.MinTime, tx.MaxTime)
-                               trID := addEntry(tr)
                                assetID := oldIss.AssetID()
 
                                builder := vmutil.NewBuilder()
@@ -130,7 +128,7 @@ func mapTx(tx *TxData) (headerID bc.Hash, hdr *bc.TxHeader, entryMap map[bc.Hash
                                builder.AddOp(vm.OP_ASSET).AddData(assetID.Bytes()).AddOp(vm.OP_EQUAL)
                                prog, _ := builder.Build() // error is impossible
 
-                               nonce := bc.NewNonce(&bc.Program{VmVersion: 1, Code: prog}, &trID)
+                               nonce := bc.NewNonce(&bc.Program{VmVersion: 1, Code: prog})
                                anchorID = addEntry(nonce)
                                setAnchored = nonce.SetAnchored
                        } else if firstSpend != nil {
index bf1fda3..8458833 100644 (file)
@@ -9,15 +9,13 @@ import "io"
 func (Nonce) typ() string { return "nonce1" }
 func (n *Nonce) writeForHash(w io.Writer) {
        mustWriteForHash(w, n.Program)
-       mustWriteForHash(w, n.TimeRangeId)
        mustWriteForHash(w, n.ExtHash)
 }
 
 // NewNonce creates a new Nonce.
-func NewNonce(p *Program, trID *Hash) *Nonce {
+func NewNonce(p *Program) *Nonce {
        return &Nonce{
-               Program:     p,
-               TimeRangeId: trID,
+               Program: p,
        }
 }
 
index 36b51bf..9b22404 100644 (file)
@@ -195,25 +195,12 @@ func checkValid(vs *validationState, e bc.Entry) (err error) {
                }
 
        case *bc.Nonce:
+               //TODO: add block heigh range check on the control program
                gasLeft, err := vm.Verify(NewTxVMContext(vs.tx, e, e.Program, e.WitnessArguments), int64(vs.gas.gasLeft))
                vs.gas.updateUsage(gasLeft)
                if err != nil {
                        return errors.Wrap(err, "checking nonce program")
                }
-               tr, err := vs.tx.TimeRange(*e.TimeRangeId)
-               if err != nil {
-                       return errors.Wrap(err, "getting nonce timerange")
-               }
-               vs2 := *vs
-               vs2.entryID = *e.TimeRangeId
-               err = checkValid(&vs2, tr)
-               if err != nil {
-                       return errors.Wrap(err, "checking nonce timerange")
-               }
-
-               if tr.MinTimeMs == 0 || tr.MaxTimeMs == 0 {
-                       return errZeroTime
-               }
 
                if vs.tx.Version == 1 && e.ExtHash != nil && !e.ExtHash.IsZero() {
                        return errNonemptyExtHash
@@ -243,17 +230,6 @@ func checkValid(vs *validationState, e bc.Entry) (err error) {
                        return errNonemptyExtHash
                }
 
-       case *bc.TimeRange:
-               if e.MinTimeMs > vs.tx.MinTimeMs {
-                       return errBadTimeRange
-               }
-               if e.MaxTimeMs > 0 && e.MaxTimeMs < vs.tx.MaxTimeMs {
-                       return errBadTimeRange
-               }
-               if vs.tx.Version == 1 && e.ExtHash != nil && !e.ExtHash.IsZero() {
-                       return errNonemptyExtHash
-               }
-
        case *bc.Issuance:
                computedAssetID := e.WitnessAssetDefinition.ComputeAssetID()
                if computedAssetID != *e.Value.AssetId {
index 584c3f4..7e07262 100644 (file)
@@ -128,46 +128,6 @@ func TestTxValidation(t *testing.T) {
                        },
                },
                {
-                       desc: "nonce timerange misordered",
-                       f: func() {
-                               iss := txIssuance(t, tx, 0)
-                               nonce := tx.Entries[*iss.AnchorId].(*bc.Nonce)
-                               tr := tx.Entries[*nonce.TimeRangeId].(*bc.TimeRange)
-                               tr.MinTimeMs = tr.MaxTimeMs + 1
-                       },
-                       err: errBadTimeRange,
-               },
-               {
-                       desc: "nonce timerange disagrees with tx timerange",
-                       f: func() {
-                               iss := txIssuance(t, tx, 0)
-                               nonce := tx.Entries[*iss.AnchorId].(*bc.Nonce)
-                               tr := tx.Entries[*nonce.TimeRangeId].(*bc.TimeRange)
-                               tr.MaxTimeMs = tx.MaxTimeMs - 1
-                       },
-                       err: errBadTimeRange,
-               },
-               {
-                       desc: "nonce timerange exthash nonempty",
-                       f: func() {
-                               iss := txIssuance(t, tx, 0)
-                               nonce := tx.Entries[*iss.AnchorId].(*bc.Nonce)
-                               tr := tx.Entries[*nonce.TimeRangeId].(*bc.TimeRange)
-                               tr.ExtHash = newHash(1)
-                       },
-                       err: errNonemptyExtHash,
-               },
-               {
-                       desc: "nonce timerange exthash nonempty, but that's OK",
-                       f: func() {
-                               tx.Version = 2
-                               iss := txIssuance(t, tx, 0)
-                               nonce := tx.Entries[*iss.AnchorId].(*bc.Nonce)
-                               tr := tx.Entries[*nonce.TimeRangeId].(*bc.TimeRange)
-                               tr.ExtHash = newHash(1)
-                       },
-               },
-               {
                        desc: "mismatched output source / mux dest position",
                        f: func() {
                                tx.Entries[*tx.ResultIds[0]].(*bc.Output).Source.Position = 1