Skip to content

Commit 0acc4ac

Browse files
committed
update readme
1 parent c3d987e commit 0acc4ac

File tree

1 file changed

+79
-68
lines changed

1 file changed

+79
-68
lines changed

x/feeds/README.md

Lines changed: 79 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ This module is used in the BandChain.
2525
- [Price Service](#price-service)
2626
- [State](#state)
2727
- [PriceService](#priceservice)
28-
- [Feed](#feed-1)
29-
- [FeedByPowerIndex](#feedbypowerindex)
28+
- [SupportedFeeds](#supportedfeeds)
3029
- [ValidatorPrice](#validatorprice)
3130
- [Price](#price-1)
3231
- [DelegatorSignal](#delegatorsignal)
32+
- [SignalTotalPower](#signaltotalpower)
33+
- [SignalTotalPowerByPowerIndex](#signaltotalpowerbypowerindex)
3334
- [Params](#params)
3435
- [Messages](#messages)
3536
- [MsgSubmitPrices](#msgsubmitprices)
@@ -38,6 +39,7 @@ This module is used in the BandChain.
3839
- [MsgSubmitSignals](#msgsubmitsignals)
3940
- [End-Block](#end-block)
4041
- [Update Prices](#update-prices)
42+
- [Update Supported Feeds](#update-supported-feeds)
4143
- [Events](#events)
4244
- [EndBlocker](#endblocker)
4345
- [Handlers](#handlers)
@@ -51,17 +53,17 @@ This module is used in the BandChain.
5153

5254
### Delegator Signal
5355

54-
A Delegator Signal is a sign or vote from a delegator, instructing the chain to provide feed service for the designated ID.
56+
A Delegator Signal is a vote from a delegator, instructing the chain to provide feed service for the designated ID.
5557

56-
A Delegator Signal consists of an ID and the power associated with that ID. The feeding interval and deviation are reduced by the sum of the power of the ID. The total power of a delegator cannot exceed their bonded delegation.
58+
A Delegator Signal consists of an ID and the power associated with that ID. The feeding interval and deviation are reduced by the sum of the power of the ID. The total power of a delegator cannot exceed their total bonded delegation.
5759

5860
### Feed
5961

60-
A Feed is a data structure containing a signal ID, its total power, and calculated interval and deviation values. Essentially, it instructs the validator regarding which signal IDs' prices need to be submitted at each specified interval or deviation.
62+
A Feed is a data structure containing a signal ID and calculated interval and deviation values from the total power. Essentially, it instructs the validator regarding which signal IDs' prices need to be submitted at each specified interval or deviation.
6163

6264
#### Feed Interval
6365

64-
The interval is calculated based on the power of its feed; the greater the power, the shorter the interval. The total power of a feed is the sum of the power of its signal IDs received from the delegators. The minimum and maximum intervals are determined by parameters called `MinInterval` and `MaxInterval`, respectively.
66+
The interval is calculated based on the total power of the signal ID; the greater the power, the shorter the interval. The total power of a signal is the sum of the power of its signal IDs received from the delegators. The minimum and maximum intervals are determined by parameters called `MinInterval` and `MaxInterval`, respectively.
6567

6668
#### Feed Deviation
6769

@@ -74,29 +76,29 @@ Deviation follows a similar logic to interval. On-chain deviation is measured in
7476
- Subsequently, the interval is calculated as the maximum of MinInterval or the floor(MaxInterval / power factor).
7577
- The deviation is then calculated as the max(`MinDeviationInThousandth`, (`MaxDeviationInThousandth` / power factor).
7678

77-
You can visualize the interval/deviation as resembling the harmonic series times MaxInterval/MaxDeviationInThousandth, with step of PowerThreshold.
79+
You can visualize the interval/deviation as resembling the harmonic series times MaxInterval/MaxDeviationInThousandth, with the step of PowerThreshold.
7880

7981
#### Supported Feeds
8082

81-
The list of currently supported feeds includes those with power exceeding the PowerThreshold parameter and ranking within the top MaxSupportedFeeds. Feeds outside of this list are considered unsupported, and validators do not need to submit their prices.
83+
The list of currently supported feeds includes those with power exceeding the PowerThreshold parameter and ranking within the top `MaxSupportedFeeds`. The supported feeds will be re-calculated on every `BlocksPerFeedsUpdate` block(s). Validators are only required to submit their prices for the supported feeds.
8284

8385
### Validator Price
8486

8587
The Validator Price refers to the price submitted by each validator before being aggregated into the final Price.
8688

87-
The module only contains the latest price of each validator and signal id.
89+
The module only contains the latest price of each validator and signal ID.
8890

8991
### Price
9092

91-
A Price is a structure that maintains the current price state for a signal id, including its current price, price status, and the most recent timestamp.
93+
A Price is a structure that maintains the current price state for a signal ID, including its current price, price status, and the most recent timestamp.
9294

93-
Once the Validator Price is submitted, it will be weighted median which weight by how latest the price and how much validator power of the owner of the price to get the most accurate and trustworthy price.
95+
Once the Validator Price is submitted, it will be weighted median which is weighted by how latest the price is and how much power the owner of the price has to get the most accurate and trustworthy price.
9496

95-
The module only contains the latest price of each signal id.
97+
The module only contains the latest price of each signal ID.
9698

9799
### Price Service
98100

99-
The On-chain Price Service is the agreed-upon version of the price service suggested for validators to use when querying prices for the feeds.
101+
The On-chain Price Service is the agreed-upon version of the price service suggested for validators to use when querying prices for the feeds. Only the admin address can update this configuration.
100102

101103
## State
102104

@@ -106,39 +108,45 @@ PriceService is stored in the global store `0x00` to hold Price Service informat
106108

107109
* PriceService: `0x00 | []byte("PriceService") -> ProtocolBuffer(PriceService)`
108110

109-
### Feed
110-
111-
The Feed is a space for holding current Feeds information.
111+
### SupportedFeeds
112112

113-
* Feed: `0x01 -> ProtocolBuffer(Feed)`
113+
SupportedFeeds is stored in the global store `0x00` to hold the list of supported feeds.
114114

115-
#### FeedByPowerIndex
116-
117-
`FeedByPowerIndex` allow to retrieve Feeds by power:
118-
`0x20| BigEndian(Power) | SignalIDLen (1 byte) | SignalID -> SignalID`
115+
* SupportedFeeds: `0x00 | []byte("SupportedFeeds") -> ProtocolBuffer(SupportedFeeds)`
119116

120117
### ValidatorPrice
121118

122-
The ValidatorPrice is a space for holding current Validator Price information.
119+
The ValidatorPrice is a space for holding the current price of signals of validators.
123120

124-
* ValidatorPrice: `0x02 -> ProtocolBuffer(ValidatorPrice)`
121+
* ValidatorPrice: `0x01 -> ProtocolBuffer(ValidatorPrice)`
125122

126123
### Price
127124

128-
The Price is a space for holding current Priceinformation.
125+
The Price is a space for holding the current price information of signals.
129126

130-
* Price: `0x03 -> ProtocolBuffer(Price)`
127+
* Price: `0x02 -> ProtocolBuffer(Price)`
131128

132129
### DelegatorSignal
133130

134-
The DelegatorSignal is a space for holding current Delegator Signals information.
131+
The DelegatorSignal is a space for holding current Delegator Signals information of validators.
132+
133+
* DelegatorSignal: `0x03 -> ProtocolBuffer(DelegatorSignals)`
134+
135+
### SignalTotalPower
136+
137+
The SignalTotalPower is a space for holding the total power of signals.
138+
139+
* SignalTotalPower: `0x04 -> ProtocolBuffer(Signal)`
135140

136-
* DelegatorSignal: `0x04 -> ProtocolBuffer(Signal)`
141+
#### SignalTotalPowerByPowerIndex
142+
143+
`SignalTotalPowerByPowerIndex` allow to retrieve SignalTotalPower by power:
144+
`0x20| BigEndian(Power) | SignalIDLen (1 byte) | SignalID -> SignalID`
137145

138146
### Params
139147

140148
The feeds module stores its params in state with the prefix of `0x10`,
141-
it can be updated with governance or the address with authority.
149+
it can be updated with governance proposal or the address with authority.
142150

143151
* Params: `0x10 | ProtocolBuffer(Params)`
144152

@@ -180,17 +188,23 @@ message Params {
180188
181189
// MaxDeviationInThousandth is the maximum limit of every feeds' deviation (in thousandth).
182190
int64 max_deviation_in_thousandth = 10;
191+
192+
// MaxSignalIDCharacters is the maximum limit of characters of a signal id.
193+
uint64 max_signal_id_characters = 11 [(gogoproto.customname) = "MaxSignalIDCharacters"];
194+
195+
// BlocksPerFeedsUpdate is the number of blocks after which the feed interval and deviation will be recalculated
196+
uint64 blocks_per_feeds_update = 12;
183197
}
184198
```
185199

186200
## Messages
187201

188-
In this section we describe the processing of the feeds messages and the corresponding updates to the state. All created/modified state objects specified by each message are defined within the [state](#state) section.
202+
In this section, we describe the processing of the `feeds` messages and the corresponding updates to the state. All created/modified state objects specified by each message are defined within the [state](#state) section.
189203

190204
### MsgSubmitPrices
191205

192206
Validator Prices are submitted using the `MsgSubmitPrices` message.
193-
The Prices will be updated at endblock using this new Validator Prices.
207+
The price of signals will be updated at the end block using these new prices from validators.
194208

195209
```protobuf
196210
// MsgSubmitPrices is the transaction message to submit multiple prices.
@@ -211,21 +225,23 @@ message MsgSubmitPrices {
211225

212226
This message is expected to fail if:
213227

214-
* validator address is not correct
215-
* validator status is not bonded
216-
* price is submitted in `CooldownTime` param
217-
* no Feed with the same signalID
228+
* validator address is not correct.
229+
* validator status is not bonded.
230+
* validator's oracle status is not active.
231+
* timestamp is too different from block time.
232+
* the price is submitted in the `CooldownTime` param.
233+
* the signals of the prices are not in the supported feeds.
218234

219235
### MsgUpdatePriceService
220236

221237
Price Service can be updated with the `MsgUpdatePriceService` message.
222-
Only assigned admin can update the Price Service.
238+
Only the assigned admin can update the Price Service.
223239

224240
```protobuf
225241
// MsgUpdatePriceService is the transaction message to update price service's information.
226242
message MsgUpdatePriceService {
227243
option (cosmos.msg.v1.signer) = "authority";
228-
option (amino.name) = "feeds/MsgUpdateParams";
244+
option (amino.name) = "feeds/MsgUpdatePriceService";
229245
230246
// Admin is the address of the admin that is performing the operation.
231247
string admin = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
@@ -237,8 +253,8 @@ message MsgUpdatePriceService {
237253

238254
This message is expected to fail if:
239255

240-
* sender address do not match `Admin` param
241-
* Price Service url is not in the correct format of an url
256+
* sender address does not match the `Admin` param.
257+
* Price Service's URL is not in the correct format of a URL.
242258

243259
### MsgUpdateParams
244260

@@ -268,10 +284,7 @@ The message handling can fail if:
268284
Delegator Signals are submitted as a batch using the MsgSubmitSignals message.
269285

270286
Batched Signals replace the previous Signals of the same delegator as a batch.
271-
Signals are registered, and their power is added to the feeds of the same SignalID.
272-
If the Feed's Interval is changed, its LastIntervalUpdateTimestamp will be marked as the block time.
273-
If the updated Feed's Power is zero, it will be deleted from the state.
274-
Every time there is an update to a Feed, `FeedByPowerIndex` will be re-indexed.
287+
Signals are registered, and their power is added to the SignalTotalPower of the same SignalID.
275288

276289
```protobuf
277290
// MsgSubmitSignals is the transaction message to submit signals
@@ -288,34 +301,40 @@ message MsgSubmitSignals {
288301

289302
The message handling can fail if:
290303

291-
* delegator address is not correct
292-
* delegator do not have less delegation than sum of the Powers
293-
* no Feed with the same signalID
304+
* The delegator's address is not correct.
305+
* The delegator has less delegation than the sum of the Powers.
306+
* The signal is not valid. (e.g. too long signal ID, power is a negative value).
294307

295308
## End-Block
296309

297310
Each abci end block call, the operations to update prices.
298311

299312
### Update Prices
300313

301-
At every end block, the Validator Price of every Supported Feed will be obtained and checked if it is within the acceptance period (1 interval).
302-
Any validator that does not submit a price within this period is considered to have miss-reported and will be deactivated, unless the Feed is in a transition period (where the interval has just been updated within TransitionTime).
303-
Accepted Validator Prices of the same SignalID will be weighted and medianed based on the recency of the price and the power of the validator who submitted the price.
304-
The medianed price is then set as the Price.
314+
At every end block, the Validator Price of all supported feeds will be obtained and checked if it is within the acceptance period (1 interval).
315+
Any validator that does not submit a price within this period is considered to have miss-reported and will be deactivated unless the Supported feeds are in a transition period.
316+
Accepted Validator Prices of the same SignalID will be weighted and median based on the recency of the price and the power of the validator who submitted the price.
317+
The median price is then set as the Price.
318+
319+
### Update supported feeds
320+
321+
At every `BlocksPerFeedsUpdate` block(s), the supported feeds will be re-calculated based on the parameters of the module (e.g. `MinInterval`, `MaxSupportedFeeds`).
305322

306323
## Events
307324

308325
The feeds module emits the following events:
309326

310327
### EndBlocker
311328

312-
| Type | Attribute Key | Attribute Value |
313-
| ---------------------- | ------------- | --------------- |
314-
| calculate_price_failed | signal_id | {signalID} |
315-
| calculate_price_failed | error_message | {error} |
316-
| update_price | signal_id | {signalID} |
317-
| update_price | price | {price} |
318-
| update_price | timestamp | {timestamp} |
329+
| Type | Attribute Key | Attribute Value |
330+
| ----------------------- | --------------------- | --------------- |
331+
| calculate_price_failed | signal_id | {signalID} |
332+
| calculate_price_failed | error_message | {error} |
333+
| update_price | signal_id | {signalID} |
334+
| update_price | price | {price} |
335+
| update_price | timestamp | {timestamp} |
336+
| updated_supported_feeds | last_update_timestamp | {timestamp} |
337+
| updated_supported_feeds | last_update_block | {block_height} |
319338

320339
### Handlers
321340

@@ -346,15 +365,7 @@ The feeds module emits the following events:
346365

347366
#### MsgSubmitSignals
348367

349-
| Type | Attribute Key | Attribute Value |
350-
| ------------ | ----------------------- | ----------------------- |
351-
| update_feed | signal_id | {signalID} |
352-
| update_feed | power | {power} |
353-
| update_feed | interval | {interval} |
354-
| update_feed | timestamp | {timestamp} |
355-
| update_feed | deviation_in_thousandth | {deviationInThousandth} |
356-
| deleate_feed | signal_id | {signalID} |
357-
| deleate_feed | power | {power} |
358-
| deleate_feed | interval | {interval} |
359-
| deleate_feed | timestamp | {timestamp} |
360-
| deleate_feed | deviation_in_thousandth | {deviationInThousandth} |
368+
| Type | Attribute Key | Attribute Value |
369+
| ------------------------- | ------------- | --------------- |
370+
| update_signal_total_power | signal_id | {signalID} |
371+
| update_signal_total_power | power | {power} |

0 commit comments

Comments
 (0)