diff --git a/docs/protocols/alpha.rst b/docs/protocols/alpha.rst index f9cc0cf8768309025019b6e38ce05c3123fa9938..8174961a0b257d8a131c17250f9f637b81f1ddec 100644 --- a/docs/protocols/alpha.rst +++ b/docs/protocols/alpha.rst @@ -51,3 +51,5 @@ Internal - Fail earlier when a smart rollup commitment is in conflict when cementing. (MR :gl:`!8128`) + +- split smart rollup origination fct for readibility. (MR :gl:`!8276`) diff --git a/src/proto_alpha/lib_protocol/sc_rollup_storage.ml b/src/proto_alpha/lib_protocol/sc_rollup_storage.ml index ef23b9092f14c2e07006ce9001cff3b52c5b39d2..7333f2c6c917951e39faad960fc7dc6b1324e91e 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_storage.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_storage.ml @@ -29,10 +29,12 @@ module Store = Storage.Sc_rollup module Commitment = Sc_rollup_commitment_repr module Commitment_hash = Commitment.Hash -(** [address_from_nonce ctxt nonce] produces an address completely determined by - an operation hash and an origination counter, and accounts for gas spent. *) -let address_from_nonce ctxt nonce = +(** [new_address ctxt] produces an address completely + determined by an operation hash and an origination counter, and + accounts for gas spent. *) +let new_address ctxt = let open Result_syntax in + let* ctxt, nonce = Raw_context.increment_origination_nonce ctxt in let* ctxt = Raw_context.consume_gas ctxt Sc_rollup_costs.Constants.cost_serialize_nonce in @@ -47,26 +49,21 @@ let address_from_nonce ctxt nonce = in (ctxt, Sc_rollup_repr.Address.hash_bytes [nonce_bytes]) -let originate ctxt ~kind ~parameters_ty ~genesis_commitment = +let init_genesis_info ctxt address genesis_commitment = let open Lwt_result_syntax in - let*? ctxt, genesis_commitment_hash = + let level = (Raw_context.current_level ctxt).level in + let*? ctxt, commitment_hash = Sc_rollup_commitment_storage.hash ctxt genesis_commitment in - let*? ctxt, nonce = Raw_context.increment_origination_nonce ctxt in - let*? ctxt, address = address_from_nonce ctxt nonce in - let* ctxt, pvm_kind_size = Store.PVM_kind.init ctxt address kind in - let origination_level = (Raw_context.current_level ctxt).level in - let* ctxt, genesis_info_size = - Store.Genesis_info.init - ctxt - address - {commitment_hash = genesis_commitment_hash; level = origination_level} - in - let* ctxt, param_ty_size_diff = - Store.Parameters_type.init ctxt address parameters_ty - in - let* ctxt = Sc_rollup_staker_index_storage.init ctxt address in - let* ctxt, lcc_size_diff = + let genesis_info = Commitment.{commitment_hash; level} in + let* ctxt, size = Store.Genesis_info.init ctxt address genesis_info in + return (ctxt, genesis_info, size) + +let init_commitment_storage ctxt address + ({commitment_hash = genesis_commitment_hash; level = origination_level} : + Commitment.genesis_info) genesis_commitment = + let open Lwt_result_syntax in + let* ctxt, lcc_size = Store.Last_cemented_commitment.init ctxt address genesis_commitment_hash in let* ctxt, commitment_size_diff = @@ -104,17 +101,38 @@ let originate ctxt ~kind ~parameters_ty ~genesis_commitment = origination_level [genesis_commitment_hash] in + return + ( ctxt, + lcc_size + commitment_size_diff + commitment_added_size_diff + + commitment_first_publication_level_diff + + commitments_per_inbox_level_diff ) + +let originate ctxt ~kind ~parameters_ty ~genesis_commitment = + let open Lwt_result_syntax in + let*? ctxt, address = new_address ctxt in + let* ctxt, pvm_kind_size = Store.PVM_kind.init ctxt address kind in + let* ctxt, param_ty_size = + Store.Parameters_type.init ctxt address parameters_ty + in + let* ctxt = Sc_rollup_staker_index_storage.init ctxt address in + let* ctxt, genesis_info, genesis_info_size_diff = + init_genesis_info ctxt address genesis_commitment + in + let* ctxt, commitment_size_diff = + init_commitment_storage ctxt address genesis_info genesis_commitment + in + (* TODO: https://gitlab.com/tezos/tezos/-/issues/4551 + There is no need to have both `origination_size` and the size of storage. + We should remove one of them. *) let addresses_size = 2 * Sc_rollup_repr.Address.size in let stored_kind_size = 2 (* because tag_size of kind encoding is 16bits. *) in let origination_size = Constants_storage.sc_rollup_origination_size ctxt in let size = Z.of_int - (origination_size + stored_kind_size + addresses_size + lcc_size_diff - + commitment_size_diff + commitment_added_size_diff - + commitment_first_publication_level_diff + param_ty_size_diff - + pvm_kind_size + genesis_info_size + commitments_per_inbox_level_diff) + (origination_size + stored_kind_size + addresses_size + param_ty_size + + pvm_kind_size + genesis_info_size_diff + commitment_size_diff) in - return (address, size, genesis_commitment_hash, ctxt) + return (address, size, genesis_info.commitment_hash, ctxt) let kind ctxt address = let open Lwt_result_syntax in