fix: carry immutable hash in command dispatch
This commit is contained in:
@@ -23,6 +23,7 @@ type DispatchCandidate struct {
|
||||
Revision uint64
|
||||
IssueTime time.Time
|
||||
QueueExpiryTime *time.Time
|
||||
ImmutableSHA256 [32]byte
|
||||
ExecutionSpec []byte
|
||||
}
|
||||
|
||||
@@ -51,13 +52,13 @@ func (store *Store) ClaimNextDispatch(ctx context.Context, clientID string, gene
|
||||
WHERE client_id = ? AND lifecycle = 1 AND queue_expiry_time IS NOT NULL AND queue_expiry_time <= ?`, now.UTC().UnixNano(), clientID, now.UTC().UnixNano()); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var encodedIssue, stored []byte
|
||||
var encodedIssue, stored, immutableHash []byte
|
||||
var revision uint64
|
||||
var issueTime int64
|
||||
var expiry sql.NullInt64
|
||||
var rawBytes uint64
|
||||
err = tx.QueryRowContext(ctx, `SELECT issue_uuid, revision, issue_time, queue_expiry_time, execution_spec, execution_spec_raw_bytes
|
||||
FROM commands WHERE client_id = ? AND lifecycle = 1 ORDER BY issue_time, issue_uuid LIMIT 1`, clientID).Scan(&encodedIssue, &revision, &issueTime, &expiry, &stored, &rawBytes)
|
||||
err = tx.QueryRowContext(ctx, `SELECT issue_uuid, revision, issue_time, queue_expiry_time, immutable_request_sha256, execution_spec, execution_spec_raw_bytes
|
||||
FROM commands WHERE client_id = ? AND lifecycle = 1 ORDER BY issue_time, issue_uuid LIMIT 1`, clientID).Scan(&encodedIssue, &revision, &issueTime, &expiry, &immutableHash, &stored, &rawBytes)
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
if err := tx.Commit(); err != nil {
|
||||
return nil, err
|
||||
@@ -67,11 +68,13 @@ FROM commands WHERE client_id = ? AND lifecycle = 1 ORDER BY issue_time, issue_u
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(encodedIssue) != 16 {
|
||||
if len(encodedIssue) != 16 || len(immutableHash) != 32 {
|
||||
return nil, ErrInvalidSegmentRecord
|
||||
}
|
||||
var issue domain.UUID
|
||||
copy(issue[:], encodedIssue)
|
||||
var immutable [32]byte
|
||||
copy(immutable[:], immutableHash)
|
||||
spec, err := decompressCommandSpec(stored, rawBytes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -90,7 +93,7 @@ FROM commands WHERE client_id = ? AND lifecycle = 1 ORDER BY issue_time, issue_u
|
||||
if err := tx.Commit(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
candidate := &DispatchCandidate{IssueUUID: issue, Revision: revision, IssueTime: time.Unix(0, issueTime).UTC(), ExecutionSpec: spec}
|
||||
candidate := &DispatchCandidate{IssueUUID: issue, Revision: revision, IssueTime: time.Unix(0, issueTime).UTC(), ImmutableSHA256: immutable, ExecutionSpec: spec}
|
||||
if expiry.Valid {
|
||||
value := time.Unix(0, expiry.Int64).UTC()
|
||||
candidate.QueueExpiryTime = &value
|
||||
|
||||
Reference in New Issue
Block a user