event_config.gno
3.43 Kb · 107 lines
1package core
2
3import "gno.land/r/onbloc/ibc/union/access"
4
5const (
6 defaultMaxEventAttrValueLen = 4096
7 defaultMaxEventAttrPairs = 50
8)
9
10var eventConfig = DefaultEventConfig()
11
12// EventConfig controls host event attribute splitting and sizing.
13type EventConfig struct {
14 // SplitEventAttrs controls whether large event attributes are emitted as
15 // indexed columns and whether split-dependent size checks are enforced.
16 SplitEventAttrs bool
17
18 // MaxEventAttrValueLen is the maximum value length of each split event
19 // attribute column.
20 MaxEventAttrValueLen uint
21
22 // MaxEventAttrPairs is the shared key/value attr-pair budget for one host
23 // event: both the max packet_data columns allowed when packet_data size
24 // checks are enforced solo, and the combined pair budget IsValidEventSize
25 // checks across packet_data plus whatever else lands in the same event
26 // (ack, relayerMsg, marketMakerMsg). Mirrors chain.Emit's own
27 // MaxEventPairs ceiling (64), kept comfortably under it to leave room for
28 // the event's other fixed attrs.
29 MaxEventAttrPairs uint
30}
31
32// NewEventConfig constructs an EventConfig value. SetEventConfig validates the
33// value before storing it.
34func NewEventConfig(splitEventAttrs bool, maxEventAttrValueLen uint, maxEventAttrPairs uint) EventConfig {
35 return EventConfig{
36 SplitEventAttrs: splitEventAttrs,
37 MaxEventAttrValueLen: maxEventAttrValueLen,
38 MaxEventAttrPairs: maxEventAttrPairs,
39 }
40}
41
42// DefaultEventConfig returns the default host event attribute policy.
43func DefaultEventConfig() EventConfig {
44 return EventConfig{
45 SplitEventAttrs: true,
46 MaxEventAttrValueLen: defaultMaxEventAttrValueLen,
47 MaxEventAttrPairs: defaultMaxEventAttrPairs,
48 }
49}
50
51// GetEventConfig returns the current host event attribute policy.
52func GetEventConfig() EventConfig {
53 return eventConfig
54}
55
56// SetEventConfig updates the host event attribute policy.
57// The caller must be authorized for SelectorSetEventConfig.
58func SetEventConfig(cur realm, config EventConfig) {
59 access.AssertCanCall(0, cur, SelectorSetEventConfig)
60
61 setEventConfig(config)
62}
63
64// SetSplitEventAttrs updates whether large event attributes are split.
65// The caller must be authorized for SelectorSetEventConfig.
66func SetSplitEventAttrs(cur realm, splitEventAttrs bool) {
67 access.AssertCanCall(0, cur, SelectorSetEventConfig)
68
69 config := GetEventConfig()
70 config.SplitEventAttrs = splitEventAttrs
71 setEventConfig(config)
72}
73
74// SetMaxEventAttrValueLen updates the maximum value length for each split
75// event attribute column.
76// The caller must be authorized for SelectorSetEventConfig.
77func SetMaxEventAttrValueLen(cur realm, maxEventAttrValueLen uint) {
78 access.AssertCanCall(0, cur, SelectorSetEventConfig)
79
80 config := GetEventConfig()
81 config.MaxEventAttrValueLen = maxEventAttrValueLen
82 setEventConfig(config)
83}
84
85// SetMaxEventAttrPairs updates the shared event attr-pair budget.
86// The caller must be authorized for SelectorSetEventConfig.
87func SetMaxEventAttrPairs(cur realm, maxEventAttrPairs uint) {
88 access.AssertCanCall(0, cur, SelectorSetEventConfig)
89
90 config := GetEventConfig()
91 config.MaxEventAttrPairs = maxEventAttrPairs
92 setEventConfig(config)
93}
94
95func setEventConfig(config EventConfig) {
96 assertValidEventConfig(config)
97 eventConfig = config
98}
99
100func assertValidEventConfig(config EventConfig) {
101 if config.MaxEventAttrValueLen == 0 {
102 panic("max event attr value len must be positive")
103 }
104 if config.MaxEventAttrPairs == 0 {
105 panic("max event attr pairs must be positive")
106 }
107}