Skip to content

Commit

Permalink
events: Remove unsupported filters (#19617)
Browse files Browse the repository at this point in the history
## Description

This PR removes EventFilters from JSON-RPC that aren't supported already
by fullnode-backed JSON-RPC:

- Combination filters (`All`, `Any`, `Not`, `And`, `Or`)
- `Package`
- `EventField`

These filters were, however, supported by the now-deprecated
subscription system, so a question remains whether they are safe to
remove.

## Test plan

Manually tested, in particular `All: []` support, which we do still need
to keep as a way to get all filters (this was also added to the
`IndexerReader` implementation):

```
sui$ cargo run --bin sui -- --force-regenesis \
  --with-indexer --with-faucet
```

...run for some time, so that some system events accumulate, then test
that we get them from both the fullnode-backed JSONRPC and
indexer-backed:

Fullnode:
```
curl -LX POST  "http://localhost:9000" \
        --header 'Content-Type: application/json' \
        --data '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "suix_queryEvents",
  "params": [
    {
      "All": []
    },
    null,
    50,
    true
  ]
}' | jq .
```

Indexer:
```
curl -LX POST  "http://localhost:9124" \
        --header 'Content-Type: application/json' \
        --data '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "suix_queryEvents",
  "params": [
    {
      "All": []
    },
    null,
    50,
    true
  ]
}' | jq .
```

## Stack

- #19474 
- #19614 
- #19615 
- #19616 

---

## Release notes

Check each box that your changes affect. If none of the boxes relate to
your changes, release notes aren't required.

For each box you select, include information after the relevant heading
that describes the impact of your changes that a user might notice and
any actions they must take to implement updates.

- [ ] Protocol: 
- [x] Nodes (Validators and Full nodes): Remove unsupported compound
filters for querying events from the JSON-RPC schema to avoid confusion.
Remove support for compound filters from the deprecated events
subscription system.
- [x] Indexer: Remove compound filters for querying events.
- [ ] JSON-RPC: 
- [ ] GraphQL: 
- [ ] CLI: 
- [ ] Rust SDK:
- [ ] REST API:
  • Loading branch information
amnn authored Sep 30, 2024
1 parent f3784b4 commit 9c6029b
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 188 deletions.
25 changes: 1 addition & 24 deletions crates/sui-core/src/authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3923,18 +3923,7 @@ impl AuthorityState {

let limit = limit + 1;
let mut event_keys = match query {
EventFilter::All(filters) => {
if filters.is_empty() {
index_store.all_events(tx_num, event_num, limit, descending)?
} else {
return Err(SuiError::UserInputError {
error: UserInputError::Unsupported(
"This query type does not currently support filter combinations"
.to_string(),
),
});
}
}
EventFilter::All([]) => index_store.all_events(tx_num, event_num, limit, descending)?,
EventFilter::Transaction(digest) => {
index_store.events_by_transaction(&digest, tx_num, event_num, limit, descending)?
}
Expand Down Expand Up @@ -3966,18 +3955,6 @@ impl AuthorityState {
limit,
descending,
)?,
// not using "_ =>" because we want to make sure we remember to add new variants here
EventFilter::Package(_)
| EventFilter::MoveEventField { .. }
| EventFilter::Any(_)
| EventFilter::And(_, _)
| EventFilter::Or(_, _) => {
return Err(SuiError::UserInputError {
error: UserInputError::Unsupported(
"This query type is not supported by the full node.".to_string(),
),
})
}
};

// skip one event if exclusive cursor is provided,
Expand Down
14 changes: 5 additions & 9 deletions crates/sui-indexer/src/indexer_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1012,8 +1012,9 @@ impl IndexerReader {
.await;
} else {
let main_where_clause = match filter {
EventFilter::Package(package_id) => {
format!("package = '\\x{}'::bytea", package_id.to_hex())
EventFilter::All([]) => {
// No filter
"1 = 1".to_string()
}
EventFilter::MoveModule { package, module } => {
format!(
Expand All @@ -1037,14 +1038,9 @@ impl IndexerReader {
// Processed above
unreachable!()
}
EventFilter::MoveEventField { .. }
| EventFilter::All(_)
| EventFilter::Any(_)
| EventFilter::And(_, _)
| EventFilter::Or(_, _)
| EventFilter::TimeRange { .. } => {
EventFilter::TimeRange { .. } => {
return Err(IndexerError::NotSupportedError(
"This type of EventFilter is not supported.".into(),
"This type of EventFilter is not supported.".to_owned(),
));
}
};
Expand Down
49 changes: 8 additions & 41 deletions crates/sui-json-rpc-types/src/sui_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,15 +203,15 @@ fn try_into_byte(v: &Value) -> Option<u8> {
#[serde_as]
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
pub enum EventFilter {
/// Return all events.
All([Box<EventFilter>; 0]),
/// Query by sender address.
Sender(SuiAddress),
/// Return events emitted by the given transaction.
Transaction(
///digest of the transaction, as base-64 encoded string
TransactionDigest,
),
/// Return events emitted in a specified Package.
Package(ObjectID),
/// Return events emitted in a specified Move module.
/// If the event is defined in Module A but emitted in a tx with Module B,
/// query `MoveModule` by module B returns the event.
Expand Down Expand Up @@ -244,10 +244,6 @@ pub enum EventFilter {
#[serde_as(as = "DisplayFromStr")]
module: Identifier,
},
MoveEventField {
path: String,
value: Value,
},
/// Return events emitted in [start_time, end_time] interval
#[serde(rename_all = "camelCase")]
TimeRange {
Expand All @@ -260,33 +256,18 @@ pub enum EventFilter {
#[serde_as(as = "BigInt<u64>")]
end_time: u64,
},

All(Vec<EventFilter>),
Any(Vec<EventFilter>),
And(Box<EventFilter>, Box<EventFilter>),
Or(Box<EventFilter>, Box<EventFilter>),
}

impl EventFilter {
fn try_matches(&self, item: &SuiEvent) -> SuiResult<bool> {
Ok(match self {
impl Filter<SuiEvent> for EventFilter {
fn matches(&self, item: &SuiEvent) -> bool {
let _scope = monitored_scope("EventFilter::matches");
match self {
EventFilter::All([]) => true,
EventFilter::MoveEventType(event_type) => &item.type_ == event_type,
EventFilter::MoveEventField { path, value } => {
matches!(item.parsed_json.pointer(path), Some(v) if v == value)
}
EventFilter::Sender(sender) => &item.sender == sender,
EventFilter::Package(object_id) => &item.package_id == object_id,
EventFilter::MoveModule { package, module } => {
&item.transaction_module == module && &item.package_id == package
}
EventFilter::All(filters) => filters.iter().all(|f| f.matches(item)),
EventFilter::Any(filters) => filters.iter().any(|f| f.matches(item)),
EventFilter::And(f1, f2) => {
EventFilter::All(vec![*(*f1).clone(), *(*f2).clone()]).matches(item)
}
EventFilter::Or(f1, f2) => {
EventFilter::Any(vec![*(*f1).clone(), *(*f2).clone()]).matches(item)
}
EventFilter::Transaction(digest) => digest == &item.id.tx_digest,

EventFilter::TimeRange {
Expand All @@ -302,21 +283,7 @@ impl EventFilter {
EventFilter::MoveEventModule { package, module } => {
&item.type_.module == module && &ObjectID::from(item.type_.address) == package
}
})
}

pub fn and(self, other_filter: EventFilter) -> Self {
Self::All(vec![self, other_filter])
}
pub fn or(self, other_filter: EventFilter) -> Self {
Self::Any(vec![self, other_filter])
}
}

impl Filter<SuiEvent> for EventFilter {
fn matches(&self, item: &SuiEvent) -> bool {
let _scope = monitored_scope("EventFilter::matches");
self.try_matches(item).unwrap_or_default()
}
}
}

Expand Down
121 changes: 13 additions & 108 deletions crates/sui-open-rpc/spec/openrpc.json
Original file line number Diff line number Diff line change
Expand Up @@ -6106,40 +6106,41 @@
"EventFilter": {
"oneOf": [
{
"description": "Query by sender address.",
"description": "Return all events.",
"type": "object",
"required": [
"Sender"
"All"
],
"properties": {
"Sender": {
"$ref": "#/components/schemas/SuiAddress"
"All": {
"type": "array",
"maxItems": 0
}
},
"additionalProperties": false
},
{
"description": "Return events emitted by the given transaction.",
"description": "Query by sender address.",
"type": "object",
"required": [
"Transaction"
"Sender"
],
"properties": {
"Transaction": {
"$ref": "#/components/schemas/TransactionDigest"
"Sender": {
"$ref": "#/components/schemas/SuiAddress"
}
},
"additionalProperties": false
},
{
"description": "Return events emitted in a specified Package.",
"description": "Return events emitted by the given transaction.",
"type": "object",
"required": [
"Package"
"Transaction"
],
"properties": {
"Package": {
"$ref": "#/components/schemas/ObjectID"
"Transaction": {
"$ref": "#/components/schemas/TransactionDigest"
}
},
"additionalProperties": false
Expand Down Expand Up @@ -6219,28 +6220,6 @@
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"MoveEventField"
],
"properties": {
"MoveEventField": {
"type": "object",
"required": [
"path",
"value"
],
"properties": {
"path": {
"type": "string"
},
"value": true
}
}
},
"additionalProperties": false
},
{
"description": "Return events emitted in [start_time, end_time] interval",
"type": "object",
Expand Down Expand Up @@ -6275,80 +6254,6 @@
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"All"
],
"properties": {
"All": {
"type": "array",
"items": {
"$ref": "#/components/schemas/EventFilter"
}
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"Any"
],
"properties": {
"Any": {
"type": "array",
"items": {
"$ref": "#/components/schemas/EventFilter"
}
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"And"
],
"properties": {
"And": {
"type": "array",
"items": [
{
"$ref": "#/components/schemas/EventFilter"
},
{
"$ref": "#/components/schemas/EventFilter"
}
],
"maxItems": 2,
"minItems": 2
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"Or"
],
"properties": {
"Or": {
"type": "array",
"items": [
{
"$ref": "#/components/schemas/EventFilter"
},
{
"$ref": "#/components/schemas/EventFilter"
}
],
"maxItems": 2,
"minItems": 2
}
},
"additionalProperties": false
}
]
},
Expand Down
7 changes: 2 additions & 5 deletions crates/sui-sdk/examples/event_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ async fn main() -> Result<(), anyhow::Error> {
let descending = true;
let query_events = sui
.event_api()
.query_events(EventFilter::All(vec![]), None, Some(5), descending) // query first 5 events in descending order
.query_events(EventFilter::All([]), None, Some(5), descending) // query first 5 events in descending order
.await?;
println!(" *** Query events *** ");
println!("{:?}", query_events);
Expand All @@ -39,10 +39,7 @@ async fn main() -> Result<(), anyhow::Error> {
.await?;
println!("WS version {:?}", ws.api_version());

let mut subscribe = ws
.event_api()
.subscribe_event(EventFilter::All(vec![]))
.await?;
let mut subscribe = ws.event_api().subscribe_event(EventFilter::All([])).await?;

loop {
println!("{:?}", subscribe.next().await);
Expand Down
2 changes: 1 addition & 1 deletion crates/sui-sdk/src/apis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1033,7 +1033,7 @@ impl EventApi {
/// .await?;
/// let mut subscribe_all = sui
/// .event_api()
/// .subscribe_event(EventFilter::All(vec![]))
/// .subscribe_event(EventFilter::All([]))
/// .await?;
/// loop {
/// println!("{:?}", subscribe_all.next().await);
Expand Down

0 comments on commit 9c6029b

Please sign in to comment.