Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: store protocol param updates #143

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/blinklabs-io/node
go 1.22

require (
github.com/blinklabs-io/gouroboros v0.94.3
github.com/blinklabs-io/gouroboros v0.95.0
github.com/blinklabs-io/ouroboros-mock v0.3.3
github.com/dgraph-io/badger/v4 v4.3.0
github.com/glebarez/sqlite v1.11.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/blinklabs-io/gouroboros v0.94.3 h1:eR26ONYtxDA7Z8UPNyknwD95LBeSC6rzaYndM5Ai03g=
github.com/blinklabs-io/gouroboros v0.94.3/go.mod h1:lfvV4sV5tNz/qkaLiR85pKpKqPlHfAa5wFhWGbgsXZ0=
github.com/blinklabs-io/gouroboros v0.95.0 h1:UulpeG/FXsMGozGuoxPP49uUW1+SYyFZc2dohs5acKc=
github.com/blinklabs-io/gouroboros v0.95.0/go.mod h1:lfvV4sV5tNz/qkaLiR85pKpKqPlHfAa5wFhWGbgsXZ0=
github.com/blinklabs-io/ouroboros-mock v0.3.3 h1:c6jN9qcLzNQSVh3zjPE61gF33UkkRRIiNqSGBkZ10cY=
github.com/blinklabs-io/ouroboros-mock v0.3.3/go.mod h1:UXkR/8qA5w/WtkzffOIdXudgOndN99DEorgRwy4ynN8=
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
Expand Down
27 changes: 27 additions & 0 deletions state/models/pparam_update.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2024 Blink Labs Software
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package models

type PParamUpdate struct {
ID uint `gorm:"primarykey"`
AddedSlot uint64
Epoch uint64
GenesisHash [28]byte
Cbor []byte
}

func (PParamUpdate) TableName() string {
return "pparam_update"
}
14 changes: 14 additions & 0 deletions state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,20 @@ func (ls *LedgerState) handleEventChainSyncBlock(e ChainsyncEvent) error {
}
}
// XXX: generate event for each TX/UTxO?
// Protocol parameter updates
if updateEpoch, paramUpdates := tx.ProtocolParameterUpdates(); updateEpoch > 0 {
for genesisHash, update := range paramUpdates {
tmpUpdate := models.PParamUpdate{
AddedSlot: e.Point.Slot,
Epoch: updateEpoch,
GenesisHash: genesisHash,
Cbor: update.Cbor(),
}
if result := txn.Metadata().Create(&tmpUpdate); result.Error != nil {
return result.Error
}
}
}
}
return nil
})
Expand Down