Skip to content

Commit

Permalink
Merge pull request #45 from Layr-Labs/sm-numericFix
Browse files Browse the repository at this point in the history
All numeric columns need to be text to avoid potential truncation
  • Loading branch information
seanmcgary authored Sep 12, 2024
2 parents 9e6f7ad + 4650a20 commit ac1a42c
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 199 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/sqlite*
9 changes: 3 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ RUN make deps-linux

RUN make build

# FROM golang:1.22-bullseye as run
#
# RUN apt-get update
# RUN apt-get install -y vim postgresql-client
#
# COPY --from=build /build/bin/cmd /bin
FROM debian:stable-slim as run

COPY --from=build /build/bin/cmd/* /bin
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ docker run -it --rm \
-e SIDECAR_SQLITE_DB_FILE_PATH="/sqlite/sidecar.db" \
-v "$(pwd)/sqlite:/sqlite" \
--tty -i \
public.ecr.aws/z6g0f8n7/go-sidecar:latest /build/bin/cmd/sidecar
public.ecr.aws/z6g0f8n7/go-sidecar:latest /bin/sidecar
```

### Build and run a container locally
Expand All @@ -56,7 +56,7 @@ docker run \
-e "SIDECAR_SQLITE_DB_FILE_PATH=/sqlite/sidecar.db" \
-v "$(pwd)/sqlite:/sqlite" \
--tty -i \
go-sidecar:latest /build/bin/cmd/sidecar
go-sidecar:latest /bin/sidecar
```

## RPC Routes
Expand Down
10 changes: 8 additions & 2 deletions internal/eigenState/operatorShares/operatorShares.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
type OperatorShares struct {
Operator string
Strategy string
Shares string `gorm:"type:numeric"`
Shares string
BlockNumber uint64
CreatedAt time.Time
}
Expand Down Expand Up @@ -290,6 +290,7 @@ func (osm *OperatorSharesModel) prepareState(blockNumber uint64) ([]OperatorShar
// Map the existing records to a map for easier lookup
mappedRecords := make(map[SlotId]OperatorShares)
for _, record := range existingRecords {
fmt.Printf("Existing OperatorShares %+v\n", record)
slotId := NewSlotId(record.Operator, record.Strategy)
mappedRecords[slotId] = record
}
Expand All @@ -308,7 +309,12 @@ func (osm *OperatorSharesModel) prepareState(blockNumber uint64) ([]OperatorShar
if existingRecord, ok := mappedRecords[slotId]; ok {
existingShares, success := numbers.NewBig257().SetString(existingRecord.Shares, 10)
if !success {
osm.logger.Sugar().Errorw("Failed to convert existing shares to big.Int")
osm.logger.Sugar().Errorw("Failed to convert existing shares to big.Int",
zap.String("shares", existingRecord.Shares),
zap.String("operator", existingRecord.Operator),
zap.String("strategy", existingRecord.Strategy),
zap.Uint64("blockNumber", blockNumber),
)
continue
}
prepared.Shares = existingShares.Add(existingShares, newState.Shares)
Expand Down
2 changes: 1 addition & 1 deletion internal/eigenState/rewardSubmissions/rewardSubmissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type RewardSubmission struct {
Amount string
Strategy string
StrategyIndex uint64
Multiplier string `gorm:"type:numeric"`
Multiplier string
StartTimestamp *time.Time `gorm:"type:DATETIME"`
EndTimestamp *time.Time `gorm:"type:DATETIME"`
Duration uint64
Expand Down
9 changes: 7 additions & 2 deletions internal/eigenState/stakerShares/stakerShares.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
type StakerShares struct {
Staker string
Strategy string
Shares string `gorm:"type:numeric"`
Shares string
BlockNumber uint64
CreatedAt time.Time
}
Expand Down Expand Up @@ -579,7 +579,12 @@ func (ss *StakerSharesModel) prepareState(blockNumber uint64) ([]StakerSharesDif
if existingRecord, ok := mappedRecords[slotId]; ok {
existingShares, success := numbers.NewBig257().SetString(existingRecord.Shares, 10)
if !success {
ss.logger.Sugar().Errorw("Failed to convert existing shares to big.Int")
ss.logger.Sugar().Errorw("Failed to convert existing shares to big.Int",
zap.String("shares", existingRecord.Shares),
zap.String("staker", existingRecord.Staker),
zap.String("strategy", existingRecord.Strategy),
zap.Uint64("blockNumber", blockNumber),
)
continue
}
prepared.Shares = existingShares.Add(existingShares, newState.Shares)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func (m *SqliteMigration) Up(grm *gorm.DB) error {
`create table if not exists operator_shares (
operator TEXT NOT NULL,
strategy TEXT NOT NULL,
shares NUMERIC NOT NULL,
shares TEXT NOT NULL,
block_number INTEGER NOT NULL,
created_at DATETIME default current_timestamp,
unique (operator, strategy, block_number)
Expand Down
2 changes: 1 addition & 1 deletion internal/sqlite/migrations/202409082234_stakerShare/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func (m *SqliteMigration) Up(grm *gorm.DB) error {
`create table if not exists staker_shares (
staker TEXT NOT NULL,
strategy TEXT NOT NULL,
shares NUMERIC NOT NULL,
shares TEXT NOT NULL,
block_number INTEGER NOT NULL,
created_at DATETIME default current_timestamp,
unique (staker, strategy, block_number)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ func (m *SqliteMigration) Up(grm *gorm.DB) error {
avs TEXT NOT NULL,
reward_hash TEST NOT NULL,
token TEXT NOT NULL,
amount NUMERIC NOT NULL,
amount TEXT NOT NULL,
strategy TEXT NOT NULL,
strategy_index INTEGER NOT NULL,
multiplier NUMERIC NOT NULL,
multiplier TEXT NOT NULL,
start_timestamp DATETIME NOT NULL,
end_timestamp DATETIME NOT NULL,
duration INTEGER NOT NULL,
Expand Down
182 changes: 0 additions & 182 deletions internal/storage/tables.go

This file was deleted.

0 comments on commit ac1a42c

Please sign in to comment.