Proto: move back max_operation_data_length as a constants

This commit is contained in:
Grégoire Henry 2018-06-02 14:58:08 +02:00 committed by Benjamin Canou
parent 39ca91cd57
commit a5cec8fca0
25 changed files with 64 additions and 87 deletions

View File

@ -36,6 +36,7 @@ type operation = {
}
let max_block_length = 42
let max_operation_data_length = 42
let validation_passes = []
let acceptable_passes _op = []
@ -80,7 +81,8 @@ end
let precheck_block
~ancestor_context:_
~ancestor_timestamp:_
(_raw_block : block_header) =
(raw_block: block_header) =
Fitness.to_int64 raw_block.shell.fitness >>=? fun _ ->
return ()
let begin_application
@ -111,8 +113,7 @@ let finalize_block ctxt =
let message = Some (Format.asprintf "fitness <- %Ld" fitness) in
let fitness = Fitness.from_int64 fitness in
return ({ Updater.message ; context = ctxt.context ; fitness ;
max_operations_ttl = 0 ; max_operation_data_length = 0 ;
last_allowed_fork_level = 0l ;
max_operations_ttl = 0 ; last_allowed_fork_level = 0l ;
}, ())
let rpc_services = RPC_directory.empty
@ -121,6 +122,5 @@ let init ctxt block_header =
let fitness = block_header.Block_header.fitness in
let message = None in
return { Updater.message ; context = ctxt ; fitness ;
max_operations_ttl = 0 ; max_operation_data_length = 0 ;
last_allowed_fork_level = 0l ;
max_operations_ttl = 0 ; last_allowed_fork_level = 0l ;
}

View File

@ -0,0 +1,10 @@
(**************************************************************************)
(* *)
(* Copyright (c) 2014 - 2018. *)
(* Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
(* *)
(* All rights reserved. No warranty, explicit or implicit, provided. *)
(* *)
(**************************************************************************)
include Updater.PROTOCOL

View File

@ -31,7 +31,7 @@ done
sleep 2
# autogenerated from the demo source
protocol_version="PsgZ1PB2h82sTKznNbmZxtbsU432eKDv1W6cf1cJFhCFmGYSiJs"
protocol_version="PrqKneMJTqCkD5bXFb4w3nidsW9kem1DjmmchwFTHqztK7V3QRq"
$admin_client inject protocol "$test_dir/demo"
$admin_client list protocols

View File

@ -24,9 +24,6 @@ type validation_result = {
(** An optional informative message to be used as in the 'git
commit' of the block's context. *)
max_operation_data_length: int ;
(** The maximum size of operations in bytes. *)
max_operations_ttl: int ;
(** The "time-to-live" of operation for the next block: any
operations whose 'branch' is older than 'ttl' blocks in the
@ -58,9 +55,12 @@ type rpc_context = {
access to the standard library and the Environment module. *)
module type PROTOCOL = sig
(** The maximum size of block headers in bytes. *)
(** The maximum size of a block header in bytes. *)
val max_block_length: int
(** The maximum size of an operation in bytes. *)
val max_operation_data_length: int
(** The number of validation passes (length of the list) and the
operation's quota for each pass. *)
val validation_passes: quota list

View File

@ -35,7 +35,6 @@ module Make (Context : CONTEXT) = struct
context: Context.t ;
fitness: Fitness.t ;
message: string option ;
max_operation_data_length: int ;
max_operations_ttl: int ;
last_allowed_fork_level: Int32.t ;
}
@ -58,6 +57,7 @@ module Make (Context : CONTEXT) = struct
type rpc_context
type 'a tzresult
val max_block_length: int
val max_operation_data_length: int
val validation_passes: quota list
type block_header_data
val block_header_data_encoding: block_header_data Data_encoding.t
@ -578,7 +578,6 @@ module Make (Context : CONTEXT) = struct
context: Context.t ;
fitness: Fitness.t ;
message: string option ;
max_operation_data_length: int ;
max_operations_ttl: int ;
last_allowed_fork_level: Int32.t ;
}

View File

@ -28,7 +28,6 @@ module Make (Context : CONTEXT) : sig
context: Context.t ;
fitness: Fitness.t ;
message: string option ;
max_operation_data_length: int ;
max_operations_ttl: int ;
last_allowed_fork_level: Int32.t ;
}
@ -51,6 +50,7 @@ module Make (Context : CONTEXT) : sig
type rpc_context
type 'a tzresult
val max_block_length: int
val max_operation_data_length: int
val validation_passes: quota list
type block_header_data
val block_header_data_encoding: block_header_data Data_encoding.t

View File

@ -98,7 +98,7 @@ let build_raw_rpc_directory
Block_services.protocol_data ;
test_chain_status ;
max_operations_ttl = State.Block.max_operations_ttl block ;
max_operation_data_length = State.Block.max_operation_data_length block ;
max_operation_data_length = Next_proto.max_operation_data_length ;
max_block_header_length = Next_proto.max_block_length ;
operation_list_quota =
List.map

View File

@ -129,15 +129,14 @@ let apply_block
invalid_block hash @@
Too_many_operations
{ pass = i + 1 ; found = List.length ops ; max }) >>=? fun () ->
let max_size = State.Block.max_operation_data_length pred in
iter_p (fun op ->
let size = Data_encoding.Binary.length Operation.encoding op in
fail_unless
(size <= max_size)
(size <= Proto.max_operation_data_length)
(invalid_block hash @@
Oversized_operation
{ operation = Operation.hash op ;
size ; max = max_size })) ops >>=? fun () ->
size ; max = Proto.max_operation_data_length })) ops >>=? fun () ->
return ())
operations Proto.validation_passes >>=? fun () ->
let operation_hashes = List.map (List.map Operation.hash) operations in

View File

@ -49,8 +49,7 @@ let rec apply_operations apply_operation state r max_ops ~sort ops =
type prevalidation_state =
State : { proto : 'a proto ; state : 'a ;
max_number_of_operations : int ;
max_operation_data_length : int }
max_number_of_operations : int }
-> prevalidation_state
and 'a proto =
@ -64,8 +63,6 @@ let start_prevalidation
timestamp = predecessor_timestamp ;
level = predecessor_level } } =
State.Block.header predecessor in
let max_operation_data_length =
State.Block.max_operation_data_length predecessor in
State.Block.context predecessor >>= fun predecessor_context ->
Context.get_protocol predecessor_context >>= fun protocol ->
let predecessor = State.Block.hash predecessor in
@ -107,12 +104,12 @@ let start_prevalidation
(* FIXME arbitrary value, to be customisable *)
let max_number_of_operations = 1000 in
return (State { proto = (module Proto) ; state ;
max_number_of_operations ; max_operation_data_length })
max_number_of_operations })
let prevalidate
(State { proto = (module Proto) ; state ;
max_number_of_operations ; max_operation_data_length })
max_number_of_operations })
~sort (ops : (Operation_hash.t * Operation.t) list)=
let ops =
List.map
@ -145,8 +142,8 @@ let prevalidate
let size = Data_encoding.Binary.length Operation.encoding op in
if max_ops <= 0 then
fail Too_many_operations
else if size > max_operation_data_length then
fail (Oversized_operation { size ; max = max_operation_data_length })
else if size > Proto.max_operation_data_length then
fail (Oversized_operation { size ; max = Proto.max_operation_data_length })
else
Proto.apply_operation state parse_op >>=? fun (state, receipt) ->
return (state, receipt) in
@ -162,7 +159,7 @@ let prevalidate
(fun map (h, op, err) -> Operation_hash.Map.add h (op, err) map)
r.branch_refused invalid_ops } in
Lwt.return (State { proto = (module Proto) ; state ;
max_number_of_operations ; max_operation_data_length },
max_number_of_operations },
r)
let end_prevalidation (State { proto = (module Proto) ; state }) =

View File

@ -221,9 +221,8 @@ module Locked_block = struct
let header : Block_header.t = { shell ; protocol_data = MBytes.create 0 } in
Store.Block.Contents.store (store, genesis.block)
{ Store.Block.header ; message = Some "Genesis" ;
max_operations_ttl = 0 ; context ;
max_operation_data_length = 0 ;
metadata = MBytes.create 0 ;
max_operations_ttl = 0 ;
context ; metadata = MBytes.create 0 ;
} >>= fun () ->
Lwt.return header
@ -443,8 +442,6 @@ module Block = struct
let message { contents = { message } } = message
let max_operations_ttl { contents = { max_operations_ttl } } =
max_operations_ttl
let max_operation_data_length { contents = { max_operation_data_length } } =
max_operation_data_length
let is_genesis b = Block_hash.equal b.hash b.chain_state.genesis.block
@ -543,7 +540,7 @@ module Block = struct
chain_state block_header block_header_metadata
operations operations_metadata
{ Tezos_protocol_environment_shell.context ; message ;
max_operations_ttl ; max_operation_data_length } =
max_operations_ttl } =
let bytes = Block_header.to_bytes block_header in
let hash = Block_header.hash_raw bytes in
fail_unless
@ -580,7 +577,6 @@ module Block = struct
block_header ;
message ;
max_operations_ttl ;
max_operation_data_length ;
context = commit ;
metadata = block_header_metadata ;
} in

View File

@ -119,7 +119,6 @@ module Block : sig
val level: t -> Int32.t
val message: t -> string option
val max_operations_ttl: t -> int
val max_operation_data_length: t -> int
val metadata: t -> MBytes.t
val is_genesis: t -> bool

View File

@ -84,7 +84,6 @@ module Block = struct
header: Block_header.t ;
message: string option ;
max_operations_ttl: int ;
max_operation_data_length: int;
context: Context_hash.t ;
metadata: MBytes.t ;
}
@ -99,18 +98,16 @@ module Block = struct
let open Data_encoding in
conv
(fun { header ; message ; max_operations_ttl ;
max_operation_data_length ; context ; metadata } ->
context ; metadata } ->
(message, max_operations_ttl,
max_operation_data_length, context, metadata, header ))
context, metadata, header ))
(fun (message, max_operations_ttl,
max_operation_data_length, context, metadata, header ) ->
context, metadata, header ) ->
{ header ; message ; max_operations_ttl ;
max_operation_data_length ;
context ; metadata })
(obj6
(obj5
(opt "message" string)
(req "max_operations_ttl" uint16)
(req "max_operation_data_length" uint16)
(req "context" Context_hash.encoding)
(req "metadata" bytes)
(req "header" Block_header.encoding))

View File

@ -88,7 +88,6 @@ module Block : sig
header: Block_header.t ;
message: string option ;
max_operations_ttl: int ;
max_operation_data_length: int;
context: Context_hash.t ;
metadata: MBytes.t ;
}

View File

@ -96,7 +96,6 @@ let make_empty_chain (chain:State.Chain.t) n : Block_hash.t Lwt.t =
context = empty_context ;
fitness = [] ;
message = None ;
max_operation_data_length = 0 ;
max_operations_ttl = 0 ;
last_allowed_fork_level = 0l ;
} in

View File

@ -89,7 +89,6 @@ let lolblock ?(operations = []) header =
max_operations_ttl = 0 ;
message = None ;
context = Context_hash.zero ;
max_operation_data_length = 0 ;
}
let b1 = lolblock "Blop !"

View File

@ -129,9 +129,7 @@ let prepare = Init_storage.prepare
let finalize ?commit_message:message c =
let fitness = Fitness.from_int64 (Fitness.current c) in
let context = Raw_context.recover c in
let constants = Raw_context.constants c in
{ Updater.context ; fitness ; message ; max_operations_ttl = 60 ;
max_operation_data_length = constants.max_operation_data_length ;
last_allowed_fork_level =
Raw_level.to_int32 @@ Level.last_allowed_fork_level c;
}

View File

@ -300,6 +300,7 @@ module Constants : sig
proof_of_work_nonce_size : int ;
nonce_length : int ;
max_revelations_per_block : int ;
max_operation_data_length : int ;
}
val fixed_encoding: fixed Data_encoding.t
val fixed: fixed
@ -307,7 +308,7 @@ module Constants : sig
val proof_of_work_nonce_size: int
val nonce_length: int
val max_revelations_per_block: int
val max_operation_data_length: int
(** Constants parameterized by context *)
type parametric = {
@ -322,7 +323,6 @@ module Constants : sig
hard_gas_limit_per_block: Z.t ;
proof_of_work_threshold: int64 ;
dictator_pubkey: Signature.Public_key.t ;
max_operation_data_length: int ;
tokens_per_roll: Tez.t ;
michelson_maximum_type_size: int;
seed_nonce_revelation_tip: Tez.t ;
@ -351,7 +351,6 @@ module Constants : sig
val hard_storage_limit_per_block: context -> Int64.t
val proof_of_work_threshold: context -> int64
val dictator_pubkey: context -> Signature.Public_key.t
val max_operation_data_length: context -> int
val tokens_per_roll: context -> Tez.t
val michelson_maximum_type_size: context -> int
val block_reward: context -> Tez.t

View File

@ -11,36 +11,43 @@ let version_number = "\000"
let proof_of_work_nonce_size = 8
let nonce_length = 32
let max_revelations_per_block = 32
let max_operation_data_length = 16 * 1024 ; (* 16kB *)
type fixed = {
proof_of_work_nonce_size : int ;
nonce_length : int ;
max_revelations_per_block : int ;
max_operation_data_length : int ;
}
let fixed_encoding =
let open Data_encoding in
conv
(fun c ->
( c.proof_of_work_nonce_size,
(c.proof_of_work_nonce_size,
c.nonce_length,
c.max_revelations_per_block ))
(fun ( proof_of_work_nonce_size,
c.max_revelations_per_block,
c.max_operation_data_length))
(fun (proof_of_work_nonce_size,
nonce_length,
max_revelations_per_block ) ->
max_revelations_per_block,
max_operation_data_length) ->
{ proof_of_work_nonce_size ;
nonce_length ;
max_revelations_per_block ;
max_operation_data_length ;
} )
(obj3
(obj4
(req "proof_of_work_nonce_size" uint8)
(req "nonce_length" uint8)
(req "max_revelations_per_block" uint8))
(req "max_revelations_per_block" uint8)
(req "max_operation_data_length" int31))
let fixed = {
proof_of_work_nonce_size ;
nonce_length ;
max_revelations_per_block ;
max_operation_data_length ;
}
type parametric = {
@ -55,7 +62,6 @@ type parametric = {
hard_gas_limit_per_block: Z.t ;
proof_of_work_threshold: int64 ;
dictator_pubkey: Signature.Public_key.t ;
max_operation_data_length: int ;
tokens_per_roll: Tez_repr.t ;
michelson_maximum_type_size: int;
seed_nonce_revelation_tip: Tez_repr.t ;
@ -85,8 +91,6 @@ let default = {
dictator_pubkey =
Signature.Public_key.of_b58check_exn
"edpkugeDwmwuwyyD3Q5enapgEYDxZLtEUFFSrvVwXASQMVEqsvTqWu" ;
max_operation_data_length =
16 * 1024 ; (* 16kB *)
tokens_per_roll =
Tez_repr.(mul_exn one 10_000) ;
michelson_maximum_type_size = 1000 ;
@ -122,7 +126,6 @@ let parametric_encoding =
c.hard_gas_limit_per_block),
((c.proof_of_work_threshold,
c.dictator_pubkey,
c.max_operation_data_length,
c.tokens_per_roll,
c.michelson_maximum_type_size,
c.seed_nonce_revelation_tip,
@ -145,7 +148,6 @@ let parametric_encoding =
hard_gas_limit_per_block),
((proof_of_work_threshold,
dictator_pubkey,
max_operation_data_length,
tokens_per_roll,
michelson_maximum_type_size,
seed_nonce_revelation_tip,
@ -168,7 +170,6 @@ let parametric_encoding =
hard_gas_limit_per_block ;
proof_of_work_threshold ;
dictator_pubkey ;
max_operation_data_length ;
tokens_per_roll ;
michelson_maximum_type_size ;
seed_nonce_revelation_tip ;
@ -193,10 +194,9 @@ let parametric_encoding =
(req "hard_gas_limit_per_operation" z)
(req "hard_gas_limit_per_block" z))
(merge_objs
(obj10
(obj9
(req "proof_of_work_threshold" int64)
(req "dictator_pubkey" Signature.Public_key.encoding)
(req "max_operation_data_length" int31)
(req "tokens_per_roll" Tez_repr.encoding)
(req "michelson_maximum_type_size" uint16)
(req "seed_nonce_revelation_tip" Tez_repr.encoding)

View File

@ -49,9 +49,6 @@ let proof_of_work_threshold c =
let dictator_pubkey c =
let constants = Raw_context.constants c in
constants.dictator_pubkey
let max_operation_data_length c =
let constants = Raw_context.constants c in
constants.max_operation_data_length
let tokens_per_roll c =
let constants = Raw_context.constants c in
constants.tokens_per_roll

View File

@ -43,6 +43,9 @@ let acceptable_passes = Alpha_context.Operation.acceptable_passes
let max_block_length =
Alpha_context.Block_header.max_header_length
let max_operation_data_length =
Alpha_context.Constants.max_operation_data_length
let validation_passes =
Updater.[ { max_size = 32 * 1024 ; max_op = Some 32 } ; (* 32kB FIXME *)
{ max_size = 32 * 1024 ; max_op = None } ; (* 32kB FIXME *)

View File

@ -72,9 +72,6 @@ let constants_encoding =
and dictator_pubkey =
opt Signature.Public_key.(=)
default.dictator_pubkey c.dictator_pubkey
and max_operation_data_length =
opt Compare.Int.(=)
default.max_operation_data_length c.max_operation_data_length
and tokens_per_roll =
opt Tez_repr.(=)
default.tokens_per_roll c.tokens_per_roll
@ -120,7 +117,6 @@ let constants_encoding =
hard_gas_limit_per_block),
((proof_of_work_threshold,
dictator_pubkey,
max_operation_data_length,
tokens_per_roll,
michelson_maximum_type_size,
seed_nonce_revelation_tip,
@ -143,7 +139,6 @@ let constants_encoding =
hard_gas_limit_per_block),
((proof_of_work_threshold,
dictator_pubkey,
max_operation_data_length,
tokens_per_roll,
michelson_maximum_type_size,
seed_nonce_revelation_tip,
@ -180,8 +175,6 @@ let constants_encoding =
unopt default.proof_of_work_threshold proof_of_work_threshold ;
dictator_pubkey =
unopt default.dictator_pubkey dictator_pubkey ;
max_operation_data_length =
unopt default.max_operation_data_length max_operation_data_length ;
tokens_per_roll =
unopt default.tokens_per_roll tokens_per_roll ;
michelson_maximum_type_size =
@ -217,10 +210,9 @@ let constants_encoding =
(opt "hard_gas_limit_per_operation" z)
(opt "hard_gas_limit_per_block" z))
(merge_objs
(obj10
(obj9
(opt "proof_of_work_threshold" int64)
(opt "dictator_pubkey" Signature.Public_key.encoding)
(opt "max_operation_data_length" int31)
(opt "tokens_per_roll" Tez_repr.encoding)
(opt "michelson_maximum_type_size" uint16)
(opt "seed_nonce_revelation_tip" Tez_repr.encoding)

View File

@ -234,7 +234,6 @@ let genesis
?(hard_gas_limit_per_block = Constants_repr.default.hard_gas_limit_per_block)
?(proof_of_work_threshold = Int64.(neg one))
?(dictator_pubkey = Constants_repr.default.dictator_pubkey)
?(max_operation_data_length = Constants_repr.default.max_operation_data_length)
?(tokens_per_roll = Constants_repr.default.tokens_per_roll)
?(michelson_maximum_type_size = Constants_repr.default.michelson_maximum_type_size)
?(seed_nonce_revelation_tip = Constants_repr.default.seed_nonce_revelation_tip)
@ -280,7 +279,6 @@ let genesis
hard_gas_limit_per_block ;
proof_of_work_threshold ;
dictator_pubkey ;
max_operation_data_length ;
tokens_per_roll ;
michelson_maximum_type_size ;
seed_nonce_revelation_tip ;

View File

@ -72,7 +72,6 @@ val genesis:
?hard_gas_limit_per_block:Z.t ->
?proof_of_work_threshold:int64 ->
?dictator_pubkey:public_key ->
?max_operation_data_length:int ->
?tokens_per_roll:Tez_repr.tez ->
?michelson_maximum_type_size:int ->
?seed_nonce_revelation_tip:Tez_repr.tez ->

View File

@ -38,6 +38,7 @@ type operation = {
}
let max_block_length = 42
let max_operation_data_length = 0
let validation_passes = []
let acceptable_passes _op = []
@ -114,8 +115,7 @@ let finalize_block ctxt =
let message = Some (Format.asprintf "fitness <- %Ld" fitness) in
let fitness = Fitness.from_int64 fitness in
return ({ Updater.message ; context = ctxt.context ; fitness ;
max_operations_ttl = 0 ; max_operation_data_length = 0 ;
last_allowed_fork_level = 0l ;
max_operations_ttl = 0 ; last_allowed_fork_level = 0l ;
}, ())
let rpc_services = Services.rpc_services
@ -124,6 +124,5 @@ let init context block_header =
return { Updater.message = None ; context ;
fitness = block_header.Block_header.fitness ;
max_operations_ttl = 0 ;
max_operation_data_length = 0 ;
last_allowed_fork_level = block_header.level ;
}

View File

@ -78,6 +78,8 @@ let max_block_length =
delay = 0L })
+ Signature.size
let max_operation_data_length = 0
let check_signature ctxt { shell ; protocol_data = { command ; signature } } =
let bytes = Data.Command.forge shell command in
Data.Pubkey.get_pubkey ctxt >>= fun public_key ->
@ -107,7 +109,6 @@ let prepare_application ctxt command level timestamp fitness =
Updater.activate ctxt hash >>= fun ctxt ->
return { Updater.message ; context = ctxt ;
fitness ; max_operations_ttl = 0 ;
max_operation_data_length = 0 ;
last_allowed_fork_level = level ;
}
| Activate_testchain { protocol = hash ; delay } ->
@ -117,7 +118,6 @@ let prepare_application ctxt command level timestamp fitness =
Updater.fork_test_chain ctxt ~protocol:hash ~expiration >>= fun ctxt ->
return { Updater.message ; context = ctxt ; fitness ;
max_operations_ttl = 0 ;
max_operation_data_length = 0 ;
last_allowed_fork_level = Int32.succ level ;
}
@ -145,7 +145,6 @@ let begin_construction
(* Dummy result. *)
return { Updater.message = None ; context = ctxt ;
fitness ; max_operations_ttl = 0 ;
max_operation_data_length = 0 ;
last_allowed_fork_level = 0l ;
}
| Some { command ; _ }->
@ -183,6 +182,5 @@ let init ctxt block_header =
return { Updater.message = None ; context = ctxt ;
fitness = block_header.Block_header.fitness ;
max_operations_ttl = 0 ;
max_operation_data_length = 0 ;
last_allowed_fork_level = block_header.level ;
}