Skip to content

Commit

Permalink
Add helper util for properly encoding root
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmcgary committed Nov 25, 2024
1 parent 94c10be commit ab9072f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ require (
github.com/DataDog/go-libddwaf/v2 v2.4.2 // indirect
github.com/DataDog/go-tuf v1.0.2-0.5.2 // indirect
github.com/DataDog/sketches-go v1.4.2 // indirect
github.com/Layr-Labs/eigenlayer-rewards-proofs v0.2.13
github.com/Layr-Labs/eigenlayer-rewards-proofs v0.2.14-0.20241125201443-e68b50c3a470
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/StackExchange/wmi v1.2.1 // indirect
github.com/bahlo/generic-list-go v0.2.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ github.com/Layr-Labs/eigenlayer-contracts v0.4.1-holesky-pepe.0.20240813143901-0
github.com/Layr-Labs/eigenlayer-contracts v0.4.1-holesky-pepe.0.20240813143901-00fc4b95e9c1/go.mod h1:Ie8YE3EQkTHqG6/tnUS0He7/UPMkXPo/3OFXwSy0iRo=
github.com/Layr-Labs/eigenlayer-rewards-proofs v0.2.13 h1:Blb4AE+jC/vddV71w4/MQAPooM+8EVqv9w2bL4OytgY=
github.com/Layr-Labs/eigenlayer-rewards-proofs v0.2.13/go.mod h1:PD/HoyzZjxDw1tAcZw3yD0yGddo+yhmwQAi+lk298r4=
github.com/Layr-Labs/eigenlayer-rewards-proofs v0.2.14-0.20241125201443-e68b50c3a470 h1:xLZ56DyrFy4CpjM9wHR4gOxxbSn1F9qYrZRkfV2V3Ic=
github.com/Layr-Labs/eigenlayer-rewards-proofs v0.2.14-0.20241125201443-e68b50c3a470/go.mod h1:szcJU28Y/X8EPCsPesY06Z3Bx7eUagwEEogLiqqxo38=
github.com/Layr-Labs/protocol-apis v0.1.0-beta.1.0.20241031143701-1007e0c3775c h1:jgImTwABd+bgblTHy4J/nqwE2cDIAHZ3zGNgFpS9P6s=
github.com/Layr-Labs/protocol-apis v0.1.0-beta.1.0.20241031143701-1007e0c3775c/go.mod h1:prNA2/mLO5vpMZ2q78Nsn0m97wm28uiRnwO+/yOxigk=
github.com/Layr-Labs/protocol-apis v0.1.0-beta.3.0.20241122223729-1734c60ac737 h1:I/0YAw2ue150YuLNavErIQ4t7yoTDuH3nqZkOS7RTjg=
Expand Down
9 changes: 6 additions & 3 deletions pkg/updater/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package updater
import (
"context"
"fmt"
"github.com/Layr-Labs/eigenlayer-rewards-proofs/pkg/utils"
"github.com/Layr-Labs/eigenlayer-rewards-updater/internal/metrics"
"github.com/Layr-Labs/eigenlayer-rewards-updater/pkg/services"
"github.com/Layr-Labs/eigenlayer-rewards-updater/pkg/sidecar"
Expand Down Expand Up @@ -65,14 +66,16 @@ func (u *Updater) Update(ctx context.Context) (*UpdatedRoot, error) {
return nil, fmt.Errorf("failed to parse snapshot date: %w", err)
}

rootBytes := [32]byte{}
copy(rootBytes[:], []byte(rootRes.RewardsRoot))
rootBytes, err := utils.ConvertStringToBytes(rootRes.RewardsRoot)
if err != nil {
return nil, fmt.Errorf("failed to convert root to bytes: %w", err)
}

// send the merkle root to the smart contract
u.logger.Sugar().Infow("updating rewards", zap.String("new_root", rootRes.RewardsRoot))

u.logger.Sugar().Infow("Calculated timestamp", zap.Int64("calculated_until_timestamp", rewardsCalcEnd.Unix()))
if err := u.transactor.SubmitRoot(ctx, rootBytes, uint32(rewardsCalcEnd.Unix())); err != nil {
if err := u.transactor.SubmitRoot(ctx, [32]byte(rootBytes), uint32(rewardsCalcEnd.Unix())); err != nil {
metrics.GetStatsdClient().Incr(metrics.Counter_UpdateFails, nil, 1)
metrics.IncCounterUpdateRun(metrics.CounterUpdateRunsFailed)
u.logger.Sugar().Errorw("Failed to submit root", zap.Error(err))
Expand Down
6 changes: 3 additions & 3 deletions pkg/updater/updater_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package updater_test
import (
"context"
"fmt"
"github.com/Layr-Labs/eigenlayer-rewards-proofs/pkg/utils"
"github.com/Layr-Labs/eigenlayer-rewards-updater/internal/logger"
"github.com/Layr-Labs/eigenlayer-rewards-updater/internal/metrics"
"github.com/Layr-Labs/eigenlayer-rewards-updater/mocks"
Expand Down Expand Up @@ -69,10 +70,9 @@ func TestUpdaterUpdate(t *testing.T) {

expectedSnapshotDateTime, _ := time.Parse(time.DateOnly, expectedSnapshotDate)

expectedRootBytes := [32]byte{}
copy(expectedRootBytes[:], []byte(expectedRoot))
expectedRootBytes, _ := utils.ConvertStringToBytes(expectedRoot)

mockTransactor.On("SubmitRoot", mock.Anything, expectedRootBytes, uint32(expectedSnapshotDateTime.Unix())).Return(nil)
mockTransactor.On("SubmitRoot", mock.Anything, [32]byte(expectedRootBytes), uint32(expectedSnapshotDateTime.Unix())).Return(nil)

updatedRoot, err := updater.Update(ctx)
assert.Nil(t, err)
Expand Down

0 comments on commit ab9072f

Please sign in to comment.