diff --git a/src/proto_016_PtMumbai/lib_sc_rollup_node/commitment.ml b/src/proto_016_PtMumbai/lib_sc_rollup_node/commitment.ml index e9fcb6c4e348a7b01f4e7e2ff8e645f5ebee342a..d82c08e76da265bf818cd943bbd225204b816262 100644 --- a/src/proto_016_PtMumbai/lib_sc_rollup_node/commitment.ml +++ b/src/proto_016_PtMumbai/lib_sc_rollup_node/commitment.ml @@ -139,17 +139,46 @@ module Make (PVM : Pvm.S) : Commitment_sig.S with module PVM = PVM = struct compressed_state; } + let genesis_commitment (node_ctxt : _ Node_context.t) ctxt = + let open Lwt_result_syntax in + let*! pvm_state = PVM.State.find ctxt in + let*? pvm_state = + match pvm_state with + | Some pvm_state -> Ok pvm_state + | None -> error_with "PVM state for genesis commitment is not available" + in + let*! compressed_state = PVM.state_hash pvm_state in + let commitment = + Sc_rollup.Commitment. + { + predecessor = Hash.zero; + inbox_level = node_ctxt.genesis_info.level; + number_of_ticks = Sc_rollup.Number_of_ticks.zero; + compressed_state; + } + in + (* Ensure the initial state corresponds to the one of the rollup's in the + protocol. A mismatch is possible if a wrong external boot sector was + provided. *) + let commitment_hash = Sc_rollup.Commitment.hash_uncarbonated commitment in + let+ () = + fail_unless + Sc_rollup.Commitment.Hash.( + commitment_hash = node_ctxt.genesis_info.commitment_hash) + (Sc_rollup_node_errors.Invalid_genesis_state + { + expected = node_ctxt.genesis_info.commitment_hash; + actual = commitment_hash; + }) + in + commitment + let create_commitment_if_necessary (node_ctxt : _ Node_context.t) ~predecessor current_level ctxt = let open Lwt_result_syntax in if Raw_level.(current_level = node_ctxt.genesis_info.level) then - let+ genesis_commitment = - Plugin.RPC.Sc_rollup.commitment - node_ctxt.cctxt - (node_ctxt.cctxt#chain, `Head 0) - node_ctxt.rollup_address - node_ctxt.genesis_info.commitment_hash - in + let*! () = Commitment_event.compute_commitment current_level in + let+ genesis_commitment = genesis_commitment node_ctxt ctxt in Some genesis_commitment else let* last_commitment_hash = diff --git a/src/proto_016_PtMumbai/lib_sc_rollup_node/interpreter.ml b/src/proto_016_PtMumbai/lib_sc_rollup_node/interpreter.ml index 7e06f674aad109c123dfd3d50775a32a943bc4a8..132b6b921519fce21c6f7ddc3b3da5d9da706046 100644 --- a/src/proto_016_PtMumbai/lib_sc_rollup_node/interpreter.ml +++ b/src/proto_016_PtMumbai/lib_sc_rollup_node/interpreter.ml @@ -115,28 +115,6 @@ module Make (PVM : Pvm.S) : S with module PVM = PVM = struct let*! initial_state = PVM.initial_state ~empty:(PVM.State.empty ()) in let*! genesis_state = PVM.install_boot_sector initial_state boot_sector in let*! ctxt = PVM.State.set ctxt genesis_state in - (* Assert that the initial genesis state is equal to the rollup's genesis - state in the protocol. *) - let* () = - let genesis_commitment = node_ctxt.genesis_info.commitment_hash in - let*! compressed_state = PVM.state_hash genesis_state in - let our_genesis_commitment = - Sc_rollup.Commitment.( - hash_uncarbonated - { - compressed_state; - inbox_level = node_ctxt.genesis_info.level; - predecessor = Sc_rollup.Commitment.Hash.zero; - number_of_ticks = Sc_rollup.Number_of_ticks.zero; - }) - in - fail_unless - (Sc_rollup.Commitment.Hash.equal - genesis_commitment - our_genesis_commitment) - (Sc_rollup_node_errors.Invalid_genesis_state - {expected = genesis_commitment; actual = our_genesis_commitment}) - in return (ctxt, genesis_state) let state_of_head node_ctxt ctxt Layer1.{hash; level} = diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/commitment.ml b/src/proto_017_PtNairob/lib_sc_rollup_node/commitment.ml index e9fcb6c4e348a7b01f4e7e2ff8e645f5ebee342a..d82c08e76da265bf818cd943bbd225204b816262 100644 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/commitment.ml +++ b/src/proto_017_PtNairob/lib_sc_rollup_node/commitment.ml @@ -139,17 +139,46 @@ module Make (PVM : Pvm.S) : Commitment_sig.S with module PVM = PVM = struct compressed_state; } + let genesis_commitment (node_ctxt : _ Node_context.t) ctxt = + let open Lwt_result_syntax in + let*! pvm_state = PVM.State.find ctxt in + let*? pvm_state = + match pvm_state with + | Some pvm_state -> Ok pvm_state + | None -> error_with "PVM state for genesis commitment is not available" + in + let*! compressed_state = PVM.state_hash pvm_state in + let commitment = + Sc_rollup.Commitment. + { + predecessor = Hash.zero; + inbox_level = node_ctxt.genesis_info.level; + number_of_ticks = Sc_rollup.Number_of_ticks.zero; + compressed_state; + } + in + (* Ensure the initial state corresponds to the one of the rollup's in the + protocol. A mismatch is possible if a wrong external boot sector was + provided. *) + let commitment_hash = Sc_rollup.Commitment.hash_uncarbonated commitment in + let+ () = + fail_unless + Sc_rollup.Commitment.Hash.( + commitment_hash = node_ctxt.genesis_info.commitment_hash) + (Sc_rollup_node_errors.Invalid_genesis_state + { + expected = node_ctxt.genesis_info.commitment_hash; + actual = commitment_hash; + }) + in + commitment + let create_commitment_if_necessary (node_ctxt : _ Node_context.t) ~predecessor current_level ctxt = let open Lwt_result_syntax in if Raw_level.(current_level = node_ctxt.genesis_info.level) then - let+ genesis_commitment = - Plugin.RPC.Sc_rollup.commitment - node_ctxt.cctxt - (node_ctxt.cctxt#chain, `Head 0) - node_ctxt.rollup_address - node_ctxt.genesis_info.commitment_hash - in + let*! () = Commitment_event.compute_commitment current_level in + let+ genesis_commitment = genesis_commitment node_ctxt ctxt in Some genesis_commitment else let* last_commitment_hash = diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/interpreter.ml b/src/proto_017_PtNairob/lib_sc_rollup_node/interpreter.ml index 04fe446b32334a46a926e4adc777cda4408c9d9b..41ad610367b3e528955603e186853b8c0e1d644c 100644 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/interpreter.ml +++ b/src/proto_017_PtNairob/lib_sc_rollup_node/interpreter.ml @@ -115,28 +115,6 @@ module Make (PVM : Pvm.S) : S with module PVM = PVM = struct let*! initial_state = PVM.initial_state ~empty:(PVM.State.empty ()) in let*! genesis_state = PVM.install_boot_sector initial_state boot_sector in let*! ctxt = PVM.State.set ctxt genesis_state in - (* Assert that the initial genesis state is equal to the rollup's genesis - state in the protocol. *) - let* () = - let genesis_commitment = node_ctxt.genesis_info.commitment_hash in - let*! compressed_state = PVM.state_hash genesis_state in - let our_genesis_commitment = - Sc_rollup.Commitment.( - hash_uncarbonated - { - compressed_state; - inbox_level = node_ctxt.genesis_info.level; - predecessor = Sc_rollup.Commitment.Hash.zero; - number_of_ticks = Sc_rollup.Number_of_ticks.zero; - }) - in - fail_unless - (Sc_rollup.Commitment.Hash.equal - genesis_commitment - our_genesis_commitment) - (Sc_rollup_node_errors.Invalid_genesis_state - {expected = genesis_commitment; actual = our_genesis_commitment}) - in return (ctxt, genesis_state) let state_of_head node_ctxt ctxt Layer1.{hash; level} = diff --git a/src/proto_alpha/lib_sc_rollup_node/commitment.ml b/src/proto_alpha/lib_sc_rollup_node/commitment.ml index e9fcb6c4e348a7b01f4e7e2ff8e645f5ebee342a..d82c08e76da265bf818cd943bbd225204b816262 100644 --- a/src/proto_alpha/lib_sc_rollup_node/commitment.ml +++ b/src/proto_alpha/lib_sc_rollup_node/commitment.ml @@ -139,17 +139,46 @@ module Make (PVM : Pvm.S) : Commitment_sig.S with module PVM = PVM = struct compressed_state; } + let genesis_commitment (node_ctxt : _ Node_context.t) ctxt = + let open Lwt_result_syntax in + let*! pvm_state = PVM.State.find ctxt in + let*? pvm_state = + match pvm_state with + | Some pvm_state -> Ok pvm_state + | None -> error_with "PVM state for genesis commitment is not available" + in + let*! compressed_state = PVM.state_hash pvm_state in + let commitment = + Sc_rollup.Commitment. + { + predecessor = Hash.zero; + inbox_level = node_ctxt.genesis_info.level; + number_of_ticks = Sc_rollup.Number_of_ticks.zero; + compressed_state; + } + in + (* Ensure the initial state corresponds to the one of the rollup's in the + protocol. A mismatch is possible if a wrong external boot sector was + provided. *) + let commitment_hash = Sc_rollup.Commitment.hash_uncarbonated commitment in + let+ () = + fail_unless + Sc_rollup.Commitment.Hash.( + commitment_hash = node_ctxt.genesis_info.commitment_hash) + (Sc_rollup_node_errors.Invalid_genesis_state + { + expected = node_ctxt.genesis_info.commitment_hash; + actual = commitment_hash; + }) + in + commitment + let create_commitment_if_necessary (node_ctxt : _ Node_context.t) ~predecessor current_level ctxt = let open Lwt_result_syntax in if Raw_level.(current_level = node_ctxt.genesis_info.level) then - let+ genesis_commitment = - Plugin.RPC.Sc_rollup.commitment - node_ctxt.cctxt - (node_ctxt.cctxt#chain, `Head 0) - node_ctxt.rollup_address - node_ctxt.genesis_info.commitment_hash - in + let*! () = Commitment_event.compute_commitment current_level in + let+ genesis_commitment = genesis_commitment node_ctxt ctxt in Some genesis_commitment else let* last_commitment_hash = diff --git a/src/proto_alpha/lib_sc_rollup_node/interpreter.ml b/src/proto_alpha/lib_sc_rollup_node/interpreter.ml index 85e981d220405819e697fc28d27fb30161a4a959..5b2cb2fb4e4a8a97783d30e6869af6f6b405c584 100644 --- a/src/proto_alpha/lib_sc_rollup_node/interpreter.ml +++ b/src/proto_alpha/lib_sc_rollup_node/interpreter.ml @@ -132,28 +132,6 @@ module Make (PVM : Pvm.S) : S with module PVM = PVM = struct let*! initial_state = PVM.initial_state ~empty:(PVM.State.empty ()) in let*! genesis_state = PVM.install_boot_sector initial_state boot_sector in let*! ctxt = PVM.State.set ctxt genesis_state in - (* Assert that the initial genesis state is equal to the rollup's genesis - state in the protocol. *) - let* () = - let genesis_commitment = node_ctxt.genesis_info.commitment_hash in - let*! compressed_state = PVM.state_hash genesis_state in - let our_genesis_commitment = - Sc_rollup.Commitment.( - hash_uncarbonated - { - compressed_state; - inbox_level = node_ctxt.genesis_info.level; - predecessor = Sc_rollup.Commitment.Hash.zero; - number_of_ticks = Sc_rollup.Number_of_ticks.zero; - }) - in - fail_unless - (Sc_rollup.Commitment.Hash.equal - genesis_commitment - our_genesis_commitment) - (Sc_rollup_node_errors.Invalid_genesis_state - {expected = genesis_commitment; actual = our_genesis_commitment}) - in return (ctxt, genesis_state) let state_of_head node_ctxt ctxt Layer1.{hash; level} =