diff --git a/execution/execution.go b/execution/execution.go index 77f016200..6dab8d9ee 100644 --- a/execution/execution.go +++ b/execution/execution.go @@ -6,7 +6,7 @@ import ( ) // New returns a new execution. It returns an error if inputs are invalid. -func New(processHash, instanceHash, parentHash, eventHash hash.Hash, nodeKey, taskKey, price string, inputs *types.Struct, tags []string, executorHash hash.Hash) *Execution { +func New(processHash, instanceHash, parentHash, eventHash hash.Hash, nodeKey, taskKey, price string, inputs *types.Struct, tags []string, executorHash hash.Hash, confs int64) *Execution { exec := &Execution{ ProcessHash: processHash, EventHash: eventHash, @@ -17,19 +17,20 @@ func New(processHash, instanceHash, parentHash, eventHash hash.Hash, nodeKey, ta NodeKey: nodeKey, Tags: tags, Price: price, - Status: Status_Created, + Status: Status_Voting, ExecutorHash: executorHash, + Confs: confs, } exec.Hash = hash.Dump(exec) return exec } // Execute changes executions status to in progres and update its execute time. -// It returns an error if the status is different then Created. +// It returns an error if the status is different then Passed. func (execution *Execution) Execute() error { - if execution.Status != Status_Created { + if execution.Status != Status_Passed { return StatusError{ - ExpectedStatus: Status_Created, + ExpectedStatus: Status_Passed, ActualStatus: execution.Status, } } diff --git a/execution/execution.pb.go b/execution/execution.pb.go index 70c7f5530..bef95db33 100644 --- a/execution/execution.pb.go +++ b/execution/execution.pb.go @@ -32,30 +32,34 @@ type Status int32 const ( // Unknown status represents any status unknown to execution. Status_Unknown Status = 0 - // Created is an initial status after execution creation. - Status_Created Status = 1 + // Passed is an status after voting phase. + Status_Passed Status = 1 // InProgress informs that processing of execution has been started. Status_InProgress Status = 2 // Completed is a success status after execution was processed. Status_Completed Status = 3 // Failed is an error status after execution was processed. Status_Failed Status = 4 + // Voting is an initial status after execution creation. + Status_Voting Status = 5 ) var Status_name = map[int32]string{ 0: "Unknown", - 1: "Created", + 1: "Passed", 2: "InProgress", 3: "Completed", 4: "Failed", + 5: "Voting", } var Status_value = map[string]int32{ "Unknown": 0, - "Created": 1, + "Passed": 1, "InProgress": 2, "Completed": 3, "Failed": 4, + "Voting": 5, } func (x Status) String() string { @@ -99,7 +103,9 @@ type Execution struct { // price of running the exeuction. Price string `protobuf:"bytes,14,opt,name=price,proto3" json:"price,omitempty" hash:"name:14" validate:"coins"` // blockHeight where the execution was included into blockchain. - BlockHeight int64 `protobuf:"varint,15,opt,name=blockHeight,proto3" json:"blockHeight,omitempty" hash:"-"` + BlockHeight int64 `protobuf:"varint,15,opt,name=blockHeight,proto3" json:"blockHeight,omitempty" hash:"-"` + // confs is the number of conrimations the exeuction needs to have before chaingin status to passed + Confs int64 `protobuf:"varint,16,opt,name=confs,proto3" json:"confs,omitempty" hash:"-"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -137,45 +143,46 @@ func init() { func init() { proto.RegisterFile("execution.proto", fileDescriptor_776e2c5022e94aef) } var fileDescriptor_776e2c5022e94aef = []byte{ - // 598 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x54, 0x5f, 0x4f, 0xdb, 0x3e, - 0x14, 0x25, 0xb4, 0xb4, 0xf4, 0xb6, 0x94, 0xfe, 0x2c, 0xfd, 0xa4, 0x88, 0x49, 0x24, 0xf2, 0x5e, - 0xb2, 0x01, 0xc9, 0x28, 0x63, 0x7f, 0x90, 0xa6, 0x6d, 0x65, 0x4c, 0x4c, 0xd3, 0xa4, 0x29, 0x68, - 0x2f, 0x7b, 0x73, 0x13, 0x93, 0x58, 0xb4, 0x76, 0x64, 0x3b, 0x6c, 0x7c, 0xa3, 0x7d, 0x14, 0x1e, - 0xf7, 0xbc, 0x87, 0x4a, 0xdb, 0x47, 0xe0, 0x13, 0x4c, 0x71, 0x08, 0xa4, 0x4c, 0x9a, 0x26, 0xc4, - 0x5b, 0x6f, 0xef, 0x39, 0xe7, 0x1e, 0x1f, 0x5f, 0x07, 0x56, 0xe9, 0x57, 0x1a, 0xe5, 0x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, 0x3d, 0x87, 0xa5, - 0x4c, 0xb2, 0x88, 0xda, 0x7d, 0x63, 0xeb, 0xfe, 0xc5, 0xcc, 0x71, 0xea, 0x84, 0xc7, 0xf5, 0x14, - 0x23, 0xc1, 0xb8, 0xc2, 0x61, 0xc9, 0x40, 0x3e, 0x74, 0xc7, 0x13, 0x11, 0x9d, 0x1c, 0x52, 0x96, - 0xa4, 0xda, 0x5e, 0x75, 0x2d, 0xaf, 0x71, 0xe3, 0xa6, 0xea, 0x80, 0x87, 0x1f, 0xa0, 0x55, 0xbe, - 0x05, 0xd4, 0x85, 0xf6, 0x27, 0x7e, 0xc2, 0xc5, 0x17, 0x3e, 0x58, 0x28, 0x8a, 0x7d, 0x49, 0x89, - 0xa6, 0xf1, 0xc0, 0x42, 0x7d, 0x80, 0x77, 0xfc, 0xa3, 0x14, 0x89, 0xa4, 0x4a, 0x0d, 0x16, 0xd1, - 0x0a, 0x74, 0xf6, 0xc5, 0x34, 0x9b, 0xd0, 0xa2, 0xdd, 0x40, 0x00, 0xad, 0xb7, 0x84, 0x4d, 0x68, - 0x3c, 0x68, 0x8e, 0x76, 0xcf, 0x7f, 0xae, 0x2f, 0x7c, 0xfb, 0xb5, 0x6e, 0x7d, 0xfe, 0x87, 0x40, - 0xae, 0xbe, 0x95, 0xe3, 0x96, 0xd9, 0xc0, 0x9d, 0xdf, 0x01, 0x00, 0x00, 0xff, 0xff, 0xab, 0x05, - 0x78, 0x67, 0x3f, 0x05, 0x00, 0x00, + // 617 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x54, 0xdf, 0x4e, 0xd4, 0x4e, + 0x18, 0xa5, 0xec, 0x3f, 0xf6, 0xdb, 0x65, 0xe9, 0x6f, 0x92, 0x5f, 0xd2, 0x60, 0xc2, 0x36, 0xe3, + 0xcd, 0x2a, 0xd0, 0xca, 0x22, 0xfe, 0x21, 0x31, 0xea, 0x2a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 0xc7, 0x9a, 0xf5, + 0xe9, 0x1f, 0xf2, 0xbb, 0xfc, 0xb5, 0x8e, 0x9b, 0x66, 0x60, 0xb7, 0x7f, 0x05, 0x00, 0x00, 0xff, + 0xff, 0x86, 0x9f, 0x4f, 0x3b, 0x6e, 0x05, 0x00, 0x00, } func (this *Execution) Equal(that interface{}) bool { @@ -247,6 +254,9 @@ func (this *Execution) Equal(that interface{}) bool { if this.BlockHeight != that1.BlockHeight { return false } + if this.Confs != that1.Confs { + return false + } if !bytes.Equal(this.XXX_unrecognized, that1.XXX_unrecognized) { return false } diff --git a/execution/execution_test.go b/execution/execution_test.go index ac5f6c891..45b9ccde8 100644 --- a/execution/execution_test.go +++ b/execution/execution_test.go @@ -19,7 +19,7 @@ func TestNewFromService(t *testing.T) { tags = []string{"tag"} ) - execution := New(nil, hash, parentHash, eventHash, "", taskKey, "", nil, tags, nil) + execution := New(nil, hash, parentHash, eventHash, "", taskKey, "", nil, tags, nil, 0) require.NotNil(t, execution) require.Equal(t, hash, execution.InstanceHash) require.Equal(t, parentHash, execution.ParentHash) @@ -27,11 +27,12 @@ func TestNewFromService(t *testing.T) { require.Equal(t, taskKey, execution.TaskKey) require.Equal(t, (*types.Struct)(nil), execution.Inputs) require.Equal(t, tags, execution.Tags) - require.Equal(t, Status_Created, execution.Status) + require.Equal(t, Status_Voting, execution.Status) } func TestExecute(t *testing.T) { - e := New(nil, nil, nil, nil, "", "", "", nil, nil, nil) + e := New(nil, nil, nil, nil, "", "", "", nil, nil, nil, 0) + e.Status = Status_Passed require.NoError(t, e.Execute()) require.Equal(t, Status_InProgress, e.Status) require.Error(t, e.Execute()) @@ -39,7 +40,8 @@ func TestExecute(t *testing.T) { func TestComplete(t *testing.T) { var output types.Struct - e := New(nil, nil, nil, nil, "", "", "", nil, nil, nil) + e := New(nil, nil, nil, nil, "", "", "", nil, nil, nil, 0) + e.Status = Status_Passed e.Execute() require.NoError(t, e.Complete(&output)) require.Equal(t, Status_Completed, e.Status) @@ -49,7 +51,8 @@ func TestComplete(t *testing.T) { func TestFailed(t *testing.T) { err := errors.New("test") - e := New(nil, nil, nil, nil, "", "", "", nil, nil, nil) + e := New(nil, nil, nil, nil, "", "", "", nil, nil, nil, 0) + e.Status = Status_Passed e.Execute() require.NoError(t, e.Failed(err)) require.Equal(t, Status_Failed, e.Status) @@ -61,7 +64,7 @@ func TestExecutionHash(t *testing.T) { ids := make(map[string]bool) f := func(instanceHash, parentHash, eventID []byte, taskKey string, tags []string) bool { - e := New(nil, instanceHash, parentHash, eventID, "", taskKey, "", nil, tags, nil) + e := New(nil, instanceHash, parentHash, eventID, "", taskKey, "", nil, tags, nil, 0) if ids[string(e.Hash)] { return false } diff --git a/protobuf/api/execution.pb.go b/protobuf/api/execution.pb.go index 5c6a542c1..375be237e 100644 --- a/protobuf/api/execution.pb.go +++ b/protobuf/api/execution.pb.go @@ -41,7 +41,9 @@ type CreateExecutionRequest struct { NodeKey string `protobuf:"bytes,8,opt,name=nodeKey,proto3" json:"nodeKey,omitempty"` ExecutorHash github_com_mesg_foundation_engine_hash.Hash `protobuf:"bytes,9,opt,name=executorHash,proto3,customtype=github.com/mesg-foundation/engine/hash.Hash" json:"executorHash" validate:"omitempty,hash"` // price of running the execution. - Price string `protobuf:"bytes,10,opt,name=price,proto3" json:"price,omitempty" validate:"coins"` + Price string `protobuf:"bytes,10,opt,name=price,proto3" json:"price,omitempty" validate:"coins"` + // confs is the number of conrimations the exeuction needs to have before chaingin status to passed + Confs int64 `protobuf:"varint,11,opt,name=confs,proto3" json:"confs,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -106,6 +108,13 @@ func (m *CreateExecutionRequest) GetPrice() string { return "" } +func (m *CreateExecutionRequest) GetConfs() int64 { + if m != nil { + return m.Confs + } + return 0 +} + // CreateExecutionResponse defines response for execution creation. type CreateExecutionResponse struct { // Execution's hash. @@ -473,54 +482,55 @@ func init() { func init() { proto.RegisterFile("protobuf/api/execution.proto", fileDescriptor_96e2c86581f82f05) } var fileDescriptor_96e2c86581f82f05 = []byte{ - // 751 bytes of a gzipped FileDescriptorProto + // 765 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x55, 0x41, 0x6f, 0xda, 0x48, - 0x14, 0x06, 0x0c, 0x06, 0x5e, 0xa2, 0xd5, 0x6a, 0x36, 0x21, 0x0e, 0xbb, 0x8b, 0x59, 0x5f, 0x16, + 0x14, 0xc6, 0x18, 0x0c, 0x3c, 0xa2, 0xd5, 0x6a, 0x36, 0x21, 0x0e, 0xbb, 0x8b, 0x59, 0x5f, 0x16, 0xed, 0x26, 0xa6, 0x25, 0xea, 0xa5, 0x6a, 0x55, 0x89, 0x2a, 0x4d, 0xaa, 0x56, 0x4d, 0xe5, 0xa8, - 0x97, 0xde, 0x06, 0xf3, 0x02, 0xa3, 0x06, 0xdb, 0x99, 0x19, 0x47, 0x4d, 0xff, 0x43, 0xff, 0x57, - 0xa5, 0xde, 0x7a, 0xec, 0x81, 0x7b, 0xaf, 0xfc, 0x80, 0xaa, 0xf2, 0x0c, 0x60, 0x02, 0x4e, 0x0e, - 0x91, 0xc8, 0xcd, 0x33, 0xef, 0x7b, 0xf3, 0xbd, 0x37, 0xf3, 0xbd, 0xcf, 0xf0, 0x57, 0xc4, 0x43, - 0x19, 0xf6, 0xe2, 0xb3, 0x36, 0x8d, 0x58, 0x1b, 0x3f, 0xa2, 0x1f, 0x4b, 0x16, 0x06, 0xae, 0xda, - 0x26, 0x95, 0x11, 0x8a, 0x81, 0x4b, 0x23, 0x56, 0x77, 0x06, 0xe1, 0x20, 0x6c, 0xcf, 0xc1, 0xc9, - 0x4a, 0x2d, 0xd4, 0x97, 0x46, 0xd7, 0xff, 0x9c, 0x87, 0xe5, 0x55, 0x84, 0xa2, 0x2d, 0x24, 0x8f, - 0x7d, 0x39, 0x0d, 0x36, 0x96, 0x82, 0x4b, 0x54, 0xce, 0xd7, 0x12, 0xd4, 0x9e, 0x73, 0xa4, 0x12, - 0x0f, 0x67, 0x11, 0x0f, 0x2f, 0x62, 0x14, 0x92, 0x3c, 0x81, 0xb2, 0xa4, 0xe2, 0xc3, 0x2b, 0xbc, - 0xb2, 0x0a, 0xcd, 0x7c, 0xab, 0xda, 0x75, 0x26, 0x63, 0xbb, 0x71, 0x49, 0xcf, 0x59, 0x9f, 0x4a, - 0x7c, 0xec, 0x70, 0xbc, 0x88, 0x19, 0xc7, 0xfe, 0x5e, 0xc4, 0x59, 0x20, 0xa9, 0xf0, 0x19, 0x73, - 0xbc, 0x59, 0x0a, 0xd9, 0x07, 0x93, 0x05, 0x51, 0x2c, 0x85, 0x65, 0x34, 0xf3, 0xad, 0x8d, 0xce, - 0xb6, 0xab, 0x9a, 0x9a, 0x95, 0xe3, 0x9e, 0xaa, 0x2a, 0xbd, 0x29, 0x88, 0x74, 0xa0, 0x28, 0xe9, - 0x40, 0x58, 0xc5, 0xa6, 0xd1, 0xaa, 0x76, 0x1b, 0x93, 0xb1, 0x5d, 0x4f, 0x99, 0xfa, 0xec, 0x12, - 0xaf, 0xb1, 0x28, 0x2c, 0x89, 0x00, 0x22, 0xca, 0x31, 0x90, 0xc7, 0x54, 0x0c, 0xad, 0x52, 0x33, - 0xdf, 0xda, 0xec, 0xbe, 0xfd, 0x32, 0xb6, 0x73, 0xdf, 0xc7, 0xf6, 0xff, 0x03, 0x26, 0x87, 0x71, - 0xcf, 0xf5, 0xc3, 0x51, 0x3b, 0x21, 0xde, 0x3f, 0x0b, 0xe3, 0xa0, 0x4f, 0x93, 0xfe, 0xda, 0x18, - 0x0c, 0x58, 0x80, 0xed, 0x21, 0x15, 0x43, 0x37, 0x49, 0x9d, 0x8c, 0xed, 0xdd, 0x94, 0x2c, 0x1c, - 0x31, 0x89, 0xa3, 0x48, 0x5e, 0xed, 0x25, 0x00, 0xc7, 0x5b, 0xe0, 0x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 0x37, 0x8d, 0x56, 0xa5, 0xeb, 0x4e, 0x27, 0x4e, 0xe3, 0x12, 0x9f, 0xd3, 0x3e, 0x96, + 0xe4, 0xb1, 0xcb, 0xc9, 0x45, 0x4c, 0x39, 0xe9, 0xef, 0x47, 0x9c, 0x86, 0x12, 0x8b, 0x80, 0x52, + 0xd7, 0x9f, 0xa7, 0xa0, 0x03, 0xb0, 0x68, 0x18, 0xc5, 0x52, 0xd8, 0x66, 0xd3, 0x68, 0x55, 0x3b, + 0x3b, 0x9e, 0x6a, 0x6a, 0x5e, 0x8e, 0x77, 0xa6, 0xaa, 0xf4, 0x67, 0x20, 0xd4, 0x81, 0x82, 0xc4, + 0x43, 0x61, 0x17, 0x9a, 0x66, 0xab, 0xd2, 0x6d, 0x4c, 0x27, 0x4e, 0x3d, 0x65, 0xea, 0xd3, 0x4b, + 0x72, 0x8d, 0x45, 0x61, 0x51, 0x04, 0x10, 0x61, 0x4e, 0x42, 0x79, 0x82, 0xc5, 0xc8, 0x2e, 0x36, + 0x8d, 0xd6, 0x56, 0xf7, 0xed, 0x97, 0x89, 0x93, 0xfb, 0x36, 0x71, 0xfe, 0x1f, 0x52, 0x39, 0x8a, + 0x7b, 0x5e, 0xc0, 0xc6, 0xed, 0x84, 0xf8, 0x60, 0xc0, 0xe2, 0xb0, 0x8f, 0x93, 0xfe, 0xda, 0x24, + 0x1c, 0xd2, 0x90, 0xb4, 0x47, 0x58, 0x8c, 0xbc, 0x24, 0x75, 0x3a, 0x71, 0xf6, 0x52, 0x32, 0x36, + 0xa6, 0x92, 0x8c, 0x23, 0x79, 0xb5, 0x9f, 0x00, 0x5c, 0x7f, 0x89, 0x03, 0x85, 0x50, 0x21, 0x97, + 0x73, 0x42, 0x6b, 0x43, 0x84, 0x29, 0x05, 0xe2, 0x50, 0x8d, 0x38, 0x0b, 0x88, 0x10, 0x8a, 0xb1, + 0xb4, 0x21, 0xc6, 0x65, 0x12, 0x64, 0x43, 0x29, 0x64, 0x7d, 0x92, 0x3c, 0x7b, 0x39, 0x79, 0x76, + 0x7f, 0xbe, 0x44, 0x12, 0xb6, 0xb4, 0x7c, 0x18, 0x57, 0xe5, 0x54, 0x36, 0x54, 0xce, 0x35, 0x16, + 0xf4, 0x1f, 0x14, 0x23, 0x4e, 0x03, 0x62, 0x83, 0x12, 0xe1, 0xf6, 0x74, 0xe2, 0xfc, 0x9e, 0xe6, + 0x06, 0x8c, 0x86, 0xc2, 0xf5, 0x35, 0x04, 0x6d, 0x43, 0x31, 0x60, 0xe1, 0x40, 0xd8, 0xd5, 0xa6, + 0xd1, 0x32, 0x7d, 0xbd, 0x70, 0x7b, 0xb0, 0xbb, 0x26, 0x71, 0x11, 0xb1, 0x50, 0x10, 0x74, 0x0c, + 0x85, 0x84, 0xd3, 0x36, 0x54, 0x2b, 0x87, 0x77, 0x68, 0xc5, 0x57, 0x07, 0xb8, 0x9f, 0xe0, 0x8f, + 0x63, 0x22, 0xd7, 0x66, 0x28, 0xb8, 0x76, 0xfe, 0xe9, 0xdd, 0xae, 0xca, 0xce, 0x98, 0x39, 0x7d, + 0x53, 0x9a, 0xfb, 0x87, 0x09, 0xb5, 0x33, 0xc9, 0x09, 0x1e, 0xaf, 0xf1, 0x3f, 0x03, 0x6b, 0x40, + 0xcf, 0x25, 0xe1, 0xaa, 0x82, 0x6a, 0xe7, 0x5f, 0x6f, 0x6e, 0x2d, 0x5e, 0x76, 0x86, 0xf7, 0x42, + 0xc1, 0xfd, 0x59, 0x5a, 0xfd, 0xb3, 0x09, 0x96, 0xde, 0x42, 0x1e, 0x94, 0x85, 0xc4, 0x32, 0x16, + 0x44, 0xd8, 0x46, 0xd3, 0x6c, 0xfd, 0xd6, 0x41, 0xfa, 0x34, 0xe5, 0x2c, 0xde, 0x99, 0x8a, 0xf9, + 0x0b, 0x4c, 0x22, 0x17, 0x1a, 0x0a, 0x89, 0xc3, 0x80, 0x28, 0xb9, 0xe4, 0x37, 0x25, 0x97, 0x65, + 0x16, 0x74, 0x98, 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 0xb2, 0xe5, 0x63, 0xb2, 0x85, 0xb9, 0x7c, + 0x43, 0x37, 0x3d, 0x73, 0xae, 0x5b, 0x7c, 0x6f, 0xe2, 0x88, 0xf6, 0x2c, 0x25, 0xa4, 0xc3, 0x5f, + 0x01, 0x00, 0x00, 0xff, 0xff, 0x51, 0xbb, 0x0b, 0x9d, 0x21, 0x09, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. diff --git a/protobuf/api/execution.proto b/protobuf/api/execution.proto index 0f7a52148..d5ba768a5 100644 --- a/protobuf/api/execution.proto +++ b/protobuf/api/execution.proto @@ -75,6 +75,9 @@ message CreateExecutionRequest { string price = 10 [ (gogoproto.moretags) = 'validate:"coins"' ]; + + // confs is the number of conrimations the exeuction needs to have before chaingin status to passed + int64 confs = 11; } // CreateExecutionResponse defines response for execution creation. diff --git a/protobuf/api/execution_test.go b/protobuf/api/execution_test.go index 81af9facf..fa74215d6 100644 --- a/protobuf/api/execution_test.go +++ b/protobuf/api/execution_test.go @@ -45,12 +45,12 @@ func TestFilter(t *testing.T) { false, }, { - &StreamExecutionRequest_Filter{Statuses: []execution.Status{execution.Status_Created}}, - &execution.Execution{Status: execution.Status_Created}, + &StreamExecutionRequest_Filter{Statuses: []execution.Status{execution.Status_Passed}}, + &execution.Execution{Status: execution.Status_Passed}, true, }, { - &StreamExecutionRequest_Filter{Statuses: []execution.Status{execution.Status_Created}}, + &StreamExecutionRequest_Filter{Statuses: []execution.Status{execution.Status_Passed}}, &execution.Execution{Status: execution.Status_InProgress}, false, }, diff --git a/protobuf/types/execution.proto b/protobuf/types/execution.proto index 71e203c25..f2eb10fcc 100644 --- a/protobuf/types/execution.proto +++ b/protobuf/types/execution.proto @@ -16,8 +16,8 @@ enum Status { // Unknown status represents any status unknown to execution. Unknown = 0; - // Created is an initial status after execution creation. - Created = 1; + // Passed is an status after voting phase. + Passed = 1; // InProgress informs that processing of execution has been started. InProgress = 2; @@ -27,6 +27,9 @@ enum Status { // Failed is an error status after execution was processed. Failed = 4; + + // Voting is an initial status after execution creation. + Voting = 5; } // Execution represents a single execution run in engine. @@ -119,4 +122,9 @@ message Execution { int64 blockHeight = 15 [ (gogoproto.moretags) = 'hash:"-"' ]; + + // confs is the number of conrimations the exeuction needs to have before chaingin status to passed + int64 confs = 16 [ + (gogoproto.moretags) = 'hash:"-"' + ]; } diff --git a/x/execution/internal/keeper/keeper.go b/x/execution/internal/keeper/keeper.go index c17453dc2..0eae8ae88 100644 --- a/x/execution/internal/keeper/keeper.go +++ b/x/execution/internal/keeper/keeper.go @@ -99,31 +99,53 @@ func (k *Keeper) Create(ctx sdk.Context, msg types.MsgCreateExecution) (*executi msg.Request.Inputs, msg.Request.Tags, msg.Request.ExecutorHash, + msg.Request.Confs, ) exec.BlockHeight = ctx.BlockHeight() store := ctx.KVStore(k.storeKey) - if store.Has(exec.Hash) { - return nil, fmt.Errorf("execution %q already exists", exec.Hash) - } - if err := exec.Execute(); err != nil { - return nil, err - } - value, err := k.cdc.MarshalBinaryLengthPrefixed(exec) - if err != nil { - return nil, err + execExist := store.Has(exec.Hash) + + if execExist { + if err := k.cdc.UnmarshalBinaryLengthPrefixed(store.Get(exec.Hash), &exec); err != nil { + return nil, err + } + + if exec.Status != executionpb.Status_Voting { + return nil, fmt.Errorf("execution %q already exists", exec.Hash) + } + } else { + value, err := k.cdc.MarshalBinaryLengthPrefixed(exec) + if err != nil { + return nil, err + } + store.Set(exec.Hash, value) + + execAddress := sdk.AccAddress(crypto.AddressHash(exec.Hash)) + if err := k.bankKeeper.SendCoins(ctx, msg.Signer, execAddress, price); err != nil { + return nil, err + } } - if !ctx.IsCheckTx() { - M.InProgress.Add(1) + var count int64 + if exec.Confs > 0 && execExist { + // do not add exec creater to voter list. + count, err = k.addVoter(ctx, exec.Hash, msg.Signer) + if err != nil { + return nil, err + } } - execAddress := sdk.AccAddress(crypto.AddressHash(exec.Hash)) - if err := k.bankKeeper.SendCoins(ctx, msg.Signer, execAddress, price); err != nil { - return nil, err + // reached consensus + if count >= exec.Confs { + exec.Status = executionpb.Status_InProgress + store.Set(exec.Hash, k.cdc.MustMarshalBinaryLengthPrefixed(exec)) + + if !ctx.IsCheckTx() { + M.InProgress.Add(1) + } } - store.Set(exec.Hash, value) return exec, nil } @@ -182,6 +204,9 @@ func (k *Keeper) Update(ctx sdk.Context, msg types.MsgUpdateExecution) (*executi return nil, err } + // after coins distribution the list of voters is not needed anymore + store.Delete(voteKey(exec.Hash)) + store.Set(exec.Hash, value) return exec, nil } @@ -197,6 +222,7 @@ func (k *Keeper) distributePriceShares(ctx sdk.Context, execAddress, runnerAddre runnerCoins, _ := sdk.NewDecCoinsFromCoins(coins...).MulDecTruncate(runnerShare).TruncateDecimal() serviceCoins := coins.Sub(runnerCoins) + // TODO: add emitters share inputs := []bank.Input{bank.NewInput(execAddress, coins)} outputs := []bank.Output{ @@ -250,3 +276,26 @@ func (k *Keeper) List(ctx sdk.Context) ([]*executionpb.Execution, error) { iter.Close() return execs, nil } + +var voteKeyPrefix = []byte{0x01} + +func voteKey(hash hash.Hash) []byte { + return append(voteKeyPrefix, []byte(hash)...) +} + +// addVoter adds an emitter address to list of voters and returns updated voters count. +func (k *Keeper) addVoter(ctx sdk.Context, execHash hash.Hash, emitter sdk.AccAddress) (int64, error) { + store := ctx.KVStore(k.storeKey) + var voters []sdk.AccAddress + key := voteKey(execHash) + if err := k.cdc.UnmarshalBinaryLengthPrefixed(store.Get(key), &voters); err != nil { + return 0, sdkerrors.Wrapf(sdkerrors.ErrJSONUnmarshal, "can't unmarshal voters") + } + voters = append(voters, emitter) + bz, err := k.cdc.MarshalBinaryLengthPrefixed(voters) + if err != nil { + return 0, sdkerrors.Wrapf(sdkerrors.ErrJSONMarshal, "can't marshal voters") + } + store.Set(key, bz) + return int64(len(voters)), nil +}