Skip to content

Commit

Permalink
Feature: add column bridge_count (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
aopoltorzhicky authored Aug 31, 2024
1 parent 5d547d9 commit 9969cc2
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 1 deletion.
4 changes: 4 additions & 0 deletions cmd/api/docs/docs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions cmd/api/docs/swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions cmd/api/docs/swagger.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cmd/api/handler/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ var (
FirstHeight: 100,
AstriaId: testsuite.RandomHash(32),
ActionsCount: 1,
BridgeCount: 1,
Size: 10,
}
testRollupURLHash = base64.URLEncoding.EncodeToString(testRollup.AstriaId)
Expand Down
2 changes: 2 additions & 0 deletions cmd/api/handler/responses/rollup.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type Rollup struct {
FirstHeight types.Level `example:"100" json:"first_height" swaggertype:"integer"`
AstriaId []byte `example:"O0Ia+lPYYMf3iFfxBaWXCSdlhphc6d4ZoBXINov6Tjc=" json:"hash" swaggertype:"string"`
ActionsCount int64 `example:"101" json:"actions_count" swaggertype:"integer"`
BridgeCount int64 `example:"2" json:"bridge_count" swaggertype:"integer"`
Size int64 `example:"100" json:"size" swaggertype:"integer"`
}

Expand All @@ -22,6 +23,7 @@ func NewRollup(rollup *storage.Rollup) Rollup {
AstriaId: rollup.AstriaId,
FirstHeight: rollup.FirstHeight,
ActionsCount: rollup.ActionsCount,
BridgeCount: rollup.BridgeCount,
Size: rollup.Size,
}

Expand Down
1 change: 1 addition & 0 deletions cmd/api/handler/rollup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func (s *RollupTestSuite) TestGet() {
s.Require().NoError(err)
s.Require().EqualValues(1, rollup.Id)
s.Require().EqualValues(1, rollup.ActionsCount)
s.Require().EqualValues(1, rollup.BridgeCount)
s.Require().EqualValues(100, rollup.FirstHeight)
s.Require().EqualValues(10, rollup.Size)
s.Require().Equal(testRollup.AstriaId, rollup.AstriaId)
Expand Down
3 changes: 2 additions & 1 deletion internal/storage/postgres/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,10 @@ func (tx Transaction) SaveRollups(ctx context.Context, rollups ...*models.Rollup
}

query := tx.Tx().NewInsert().Model(&rs).
Column("first_height", "astria_id", "actions_count", "size").
Column("first_height", "astria_id", "actions_count", "bridge_count", "size").
On("CONFLICT ON CONSTRAINT rollup_id DO UPDATE").
Set("actions_count = added_rollup.actions_count + EXCLUDED.actions_count").
Set("bridge_count = added_rollup.bridge_count + EXCLUDED.bridge_count").
Set("size = added_rollup.size + EXCLUDED.size")

if _, err := query.Returning("xmax, id").Exec(ctx); err != nil {
Expand Down
1 change: 1 addition & 0 deletions internal/storage/rollup.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type Rollup struct {
AstriaId []byte `bun:"astria_id,unique:rollup_id" comment:"Astria rollup identity"`
FirstHeight types.Level `bun:"first_height" comment:"Block number of the first rollup occurrence"`
ActionsCount int64 `bun:"actions_count" comment:"Count of actions in which the rollup was involved"`
BridgeCount int64 `bun:"bridge_count" comment:"Count of connected bridges"`
Size int64 `bun:"size" comment:"Count bytes which was saved in the rollup"`
}

Expand Down
1 change: 1 addition & 0 deletions pkg/indexer/decode/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ func parseInitBridgeAccount(body *astria.Action_InitBridgeAccountAction, from st
Address: ctx.Addresses.Set(from, height, decimal.Zero, "", 0, 0),
Rollup: rollup,
}
rollup.BridgeCount += 1

action.Data["rollup_id"] = rollupId
action.Data["fee_asset"] = bridge.FeeAsset
Expand Down
2 changes: 2 additions & 0 deletions pkg/indexer/decode/actions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,7 @@ func TestDecodeActions(t *testing.T) {
AstriaId: message.InitBridgeAccountAction.GetRollupId().GetInner(),
FirstHeight: 1000,
ActionsCount: 1,
BridgeCount: 1,
},
},
Addresses: make([]*storage.AddressAction, 0),
Expand Down Expand Up @@ -845,6 +846,7 @@ func TestDecodeActions(t *testing.T) {
AstriaId: message.InitBridgeAccountAction.GetRollupId().GetInner(),
FirstHeight: 1000,
ActionsCount: 1,
BridgeCount: 1,
},
},
}
Expand Down

0 comments on commit 9969cc2

Please sign in to comment.