@@ -20,54 +20,12 @@ use move_core_types::{
20
20
use prost_types:: value:: Kind ;
21
21
use prost_types:: Struct ;
22
22
use prost_types:: Value ;
23
- use std:: sync:: LazyLock ;
24
- use tracing:: info;
25
23
26
24
/// This is the maximum depth of a proto message
27
25
/// The maximum depth of a proto message is 100. Given this value may be nested itself somewhere
28
26
/// we'll conservitively cap this to ~80% of that.
29
27
const MAX_DEPTH : usize = 80 ;
30
28
31
- /// Environment variable to override the default budget for deserialization. This can be set at
32
- /// runtime to change the maximum size of values that can be deserialized.
33
- const MAX_BOUND_VAR_NAME : & str = "MAX_JSON_MOVE_VALUE_SIZE" ;
34
-
35
- /// Default budget for deserialization -- we're okay to spend 1MiB on rendering a move value to
36
- /// JSON.
37
- const DEFAULT_MAX_BOUND : usize = 1024 * 1024 ;
38
-
39
- /// Budget for rendering a Move value into JSON. This sets the numbers of bytes that we
40
- /// are willing to spend on rendering field names and values when rendering a Move value into a
41
- /// JSON value.
42
- ///
43
- /// Bounded deserialization is intended for use outside of the validator, and so uses a fixed bound
44
- /// that needs to be set at startup rather than one that is configured as part of the protocol.
45
- ///
46
- /// If the environment variable `MAX_JSON_MOVE_VALUE_SIZE` is unset we default to
47
- /// `DEFAULT_MAX_BOUND` which allows 1MiB space usage on rendering a value to JSON.
48
- ///
49
- /// This is read only once and after that the value is cached. To change this value you will need
50
- /// to restart the process with the new value set (or the value unset if you wish to use the
51
- /// `DEFAULT_MAX_BOUND` value).
52
- static MAX_BOUND : LazyLock < usize > = LazyLock :: new ( || {
53
- let max_bound_opt = std:: env:: var ( MAX_BOUND_VAR_NAME )
54
- . ok ( )
55
- . and_then ( |s| s. parse ( ) . ok ( ) ) ;
56
- if let Some ( max_bound) = max_bound_opt {
57
- info ! (
58
- "Using custom value for '{}' max bound: {}" ,
59
- MAX_BOUND_VAR_NAME , max_bound
60
- ) ;
61
- max_bound
62
- } else {
63
- info ! (
64
- "Using default value for '{}' -- max bound: {}" ,
65
- MAX_BOUND_VAR_NAME , DEFAULT_MAX_BOUND
66
- ) ;
67
- DEFAULT_MAX_BOUND
68
- }
69
- } ) ;
70
-
71
29
pub struct ProtoVisitor {
72
30
/// Budget left to spend on visiting.
73
31
bound : usize ,
@@ -89,12 +47,6 @@ pub enum Error {
89
47
UnexpectedType ,
90
48
}
91
49
92
- impl Default for ProtoVisitor {
93
- fn default ( ) -> Self {
94
- Self :: new ( * MAX_BOUND )
95
- }
96
- }
97
-
98
50
impl ProtoVisitor {
99
51
pub fn new ( bound : usize ) -> Self {
100
52
Self { bound, depth : 0 }
@@ -698,7 +650,7 @@ pub(crate) mod tests {
698
650
699
651
fn json < T : serde:: Serialize > ( layout : A :: MoveTypeLayout , data : T ) -> serde_json:: Value {
700
652
let bcs = bcs:: to_bytes ( & data) . unwrap ( ) ;
701
- let proto_value = ProtoVisitor :: default ( )
653
+ let proto_value = ProtoVisitor :: new ( 1024 * 1024 )
702
654
. deserialize_value ( & bcs, & layout)
703
655
. unwrap ( ) ;
704
656
proto_value_to_json_value ( proto_value)
0 commit comments