Skip to content

Commit

Permalink
fix: update multi-miner contract to use block height
Browse files Browse the repository at this point in the history
  • Loading branch information
obycode committed Jun 21, 2023
1 parent 0c7b9d7 commit 7b0f09a
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions core-contracts/contracts/multi-miner.clar
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
(asserts! (>= (len provided-checked) signers-required) (err ERR_NOT_ENOUGH_SIGNERS))
(ok true)))

(define-read-only (make-block-commit-hash (block-data { block: (buff 32), subnet-block-height: uint, withdrawal-root: (buff 32), target-tip: (buff 32) }))
(define-read-only (make-block-commit-hash (block-data { block: (buff 32), subnet-block-height: uint, withdrawal-root: (buff 32), target-tip: (buff 32), target-height: uint }))
(let ((data-buff (unwrap-panic (to-consensus-buff? (merge block-data { multi-contract: CONTRACT_ADDRESS }))))
(data-hash (sha256 data-buff))
;; in 2.0, this is a constant: 0xe2f4d0b1eca5f1b4eb853cd7f1c843540cfb21de8bfdaa59c504a6775cd2cfe9
Expand All @@ -102,15 +102,27 @@
signers: (unwrap-panic (as-max-len? (append (get signers prior-okay) curr-signer) u9)) }))
prior-err (err prior-err)))

(define-public (commit-block (block-data { block: (buff 32), subnet-block-height: uint, withdrawal-root: (buff 32), target-tip: (buff 32) })
(signatures (list 9 (buff 65))))
(define-public (commit-block
(block-data { block: (buff 32), subnet-block-height: uint, withdrawal-root: (buff 32), target-tip: (buff 32), target-height: uint })
(signatures (list 9 (buff 65)))
)
(let ((block-data-hash (make-block-commit-hash block-data))
(signer-principals (try! (fold verify-sign-helper signatures (ok { block-hash: block-data-hash, signers: (list) })))))
;; check that the caller is a direct caller!
(asserts! (is-eq tx-sender contract-caller) (err ERR_UNAUTHORIZED_CONTRACT_CALLER))
;; check that we have enough signatures
(try! (check-miners (append (get signers signer-principals) tx-sender)))
;; execute the block commit
(as-contract (contract-call? .subnet-v2-0-0 commit-block (get block block-data) (get subnet-block-height block-data) (get target-tip block-data) (get withdrawal-root block-data)))
(as-contract
(contract-call?
.subnet-v2-0-0
commit-block
(get block block-data)
(get subnet-block-height block-data)
(get target-tip block-data)
(get target-height block-data)
(get withdrawal-root block-data)
)
)
)
)

0 comments on commit 7b0f09a

Please sign in to comment.