Skip to content

Commit

Permalink
Merge pull request #11364 from vegaprotocol/derived-keys-fix
Browse files Browse the repository at this point in the history
feat: fix add to event
  • Loading branch information
karlem authored Jun 11, 2024
2 parents d2e1a1f + 578d2d7 commit 2c13dcb
Show file tree
Hide file tree
Showing 12 changed files with 133 additions and 19 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
- [11301](https://github.com/vegaprotocol/vega/issues/11301) - Sum vesting reward bonus multiplier across all derived keys for party.
- [11329](https://github.com/vegaprotocol/vega/issues/11329) - Add source chain ID when available to transaction event attributes
- [10634](https://github.com/vegaprotocol/vega/issues/10634) - Add spam checks for orders/liquidity provision
- [11337](https://github.com/vegaprotocol/vega/issues/11337) - Enhance transaction reordering with per market control and configurable delay.
- [11337](https://github.com/vegaprotocol/vega/issues/11337) - Enhance transaction reordering with per market control and configurable delay.
- [11344](https://github.com/vegaprotocol/vega/issues/11344) - Include derived parties in accounts API
- [11268](https://github.com/vegaprotocol/vega/issues/11268) - Include derived parties vesting stats API
- [11266](https://github.com/vegaprotocol/vega/issues/11266) - Include derived parties rewards API
Expand All @@ -36,6 +36,8 @@
- [11297](https://github.com/vegaprotocol/vega/issues/11297) - Handle properly asset decimals < market decimals when uncrossing the order book upon leaving auction.
- [11304](https://github.com/vegaprotocol/vega/issues/11304) - Correctly verify pegged order offset with respect to tick size in the right units.
- [11319](https://github.com/vegaprotocol/vega/issues/11319) - Do not leak Ethereum client secrets in the logs.
- [11336](https://github.com/vegaprotocol/vega/issues/11336) - Add support for decay factor in governance recurring transfers and report the proposal amount rather than 0 when the proposal gets enacted.
- [11368](https://github.com/vegaprotocol/vega/issues/11368) - Add support for update vesting stats in REST API and fix summing the quantum balance for vesting stats.

## 0.76.1

Expand Down
19 changes: 16 additions & 3 deletions core/events/party.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
vegapb "code.vegaprotocol.io/vega/protos/vega"
eventspb "code.vegaprotocol.io/vega/protos/vega/events/v1"

"golang.org/x/exp/maps"
"golang.org/x/exp/slices"
)

Expand Down Expand Up @@ -98,13 +99,25 @@ func NewPartyProfileUpdatedEvent(ctx context.Context, p *types.PartyProfile) *Pa
return strings.Compare(a.Key, b.Key)
})

// Ensure deterministic order in event.
slices.SortStableFunc(metadata, func(a, b *vegapb.Metadata) int {
return strings.Compare(a.Key, b.Key)
})

derivedKeys := maps.Keys(p.DerivedKeys)

slices.SortStableFunc(derivedKeys, func(a, b string) int {
return strings.Compare(a, b)
})

return &PartyProfileUpdated{
Base: newBase(ctx, PartyProfileUpdatedEvent),
e: eventspb.PartyProfileUpdated{
UpdatedProfile: &vegapb.PartyProfile{
PartyId: p.PartyID.String(),
Alias: p.Alias,
Metadata: metadata,
PartyId: p.PartyID.String(),
Alias: p.Alias,
Metadata: metadata,
DerivedKeys: derivedKeys,
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion core/execution/amm/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ func (e *Engine) Confirm(

e.add(pool)
e.sendUpdate(ctx, pool)
e.parties.AssignDeriveKey(types.PartyID(pool.owner), pool.AMMParty)
e.parties.AssignDeriveKey(ctx, types.PartyID(pool.owner), pool.AMMParty)
}

// Amend takes the details of an amendment to an AMM and returns a copy of that pool with the updated curves along with the current pool.
Expand Down
2 changes: 1 addition & 1 deletion core/execution/amm/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ func getTestEngine(t *testing.T) *tstEngine {
mat := common.NewMarketActivityTracker(logging.NewTestLogger(), teams, balanceChecker, broker)

parties := cmocks.NewMockParties(ctrl)
parties.EXPECT().AssignDeriveKey(gomock.Any(), gomock.Any()).AnyTimes()
parties.EXPECT().AssignDeriveKey(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes()

eng := New(logging.NewTestLogger(), broker, col, marketID, assetID, pos, num.DecimalOne(), num.DecimalOne(), mat, parties)

Expand Down
2 changes: 1 addition & 1 deletion core/execution/common/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ type Banking interface {
}

type Parties interface {
AssignDeriveKey(party types.PartyID, derivedKey string)
AssignDeriveKey(ctx context.Context, party types.PartyID, derivedKey string)
}

type LiquidityEngine interface {
Expand Down
8 changes: 4 additions & 4 deletions core/execution/common/mocks/mocks.go

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

2 changes: 1 addition & 1 deletion core/parties/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (e *Engine) OnMinBalanceForUpdatePartyProfileUpdated(_ context.Context, min
return nil
}

func (e *Engine) AssignDeriveKey(party types.PartyID, derivedKey string) {
func (e *Engine) AssignDeriveKey(ctx context.Context, party types.PartyID, derivedKey string) {
if _, ok := e.profiles[party]; !ok {
e.profiles[party] = &types.PartyProfile{
PartyID: party,
Expand Down
6 changes: 3 additions & 3 deletions core/parties/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ func TestAssigningDerivedKeys(t *testing.T) {
require.False(t, te.engine.CheckDerivedKeyOwnership(party1, "derivedKey1"))

// Assigning derived keys create profile if it doesn't exist
te.engine.AssignDeriveKey(party1, "derivedKey1")
te.engine.AssignDeriveKey(party1, "derivedKey2")
te.engine.AssignDeriveKey(ctx, party1, "derivedKey1")
te.engine.AssignDeriveKey(ctx, party1, "derivedKey2")

require.True(t, te.engine.CheckDerivedKeyOwnership(party1, "derivedKey1"))
require.True(t, te.engine.CheckDerivedKeyOwnership(party1, "derivedKey2"))
Expand Down Expand Up @@ -162,7 +162,7 @@ func TestAssigningDerivedKeys(t *testing.T) {
}))

// Assign key for party 2
te.engine.AssignDeriveKey(party2, "derivedKey3")
te.engine.AssignDeriveKey(ctx, party2, "derivedKey3")

// Attempt using alias from party 2.
require.Error(t, te.engine.UpdateProfile(ctx, party1, &commandspb.UpdatePartyProfile{
Expand Down
4 changes: 1 addition & 3 deletions core/vesting/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ func (e *Engine) OnRewardVestingMinimumTransferUpdate(_ context.Context, minimum

func (e *Engine) OnEpochEvent(ctx context.Context, epoch types.Epoch) {
if epoch.Action == proto.EpochAction_EPOCH_ACTION_END {
e.clearMultiplierCache()
e.moveLocked()
e.distributeVested(ctx)
e.broadcastVestingStatsUpdate(ctx, epoch.Seq)
Expand Down Expand Up @@ -212,9 +213,6 @@ func (e *Engine) GetSingleAndSummedRewardBonusMultipliers(party string) (Multipl
single, foundSingle := e.rewardBonusMultiplierCache[key]
if !foundSingle {
quantumBalanceForKey := e.c.GetAllVestingQuantumBalance(key)
if quantumBalanceForKey.IsZero() {
continue
}

single.QuantumBalance = quantumBalanceForKey
single.Multiplier = e.rewardBonusMultiplier(quantumBalanceForKey)
Expand Down
99 changes: 99 additions & 0 deletions protos/data-node/api/v2/trading_data.pb.gw.go

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

2 changes: 1 addition & 1 deletion protos/embed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func Test_DataNodeBindings(t *testing.T) {
t.Run("CoreBindings should return the core http bindings", func(t *testing.T) {
bindings, err := protos.DataNodeBindings()
require.NoError(t, err)
wantCount := 117
wantCount := 118

assert.Len(t, bindings.HTTP.Rules, wantCount)

Expand Down
2 changes: 2 additions & 0 deletions protos/sources/data-node/grpc-rest-bindings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ http:
get: "/api/v2/successor_markets/{market_id}"
- selector: datanode.api.v2.TradingDataService.GetPartyActivityStreak
get: "/api/v2/party/activity/streak/{party_id}"
- selector: datanode.api.v2.TradingDataService.GetPartyVestingStats
get: "/api/v2/party/vesting/stats/{party_id}"
- selector: datanode.api.v2.TradingDataService.GetParty
get: "/api/v2/party/{party_id}"
- selector: datanode.api.v2.TradingDataService.ListParties
Expand Down

0 comments on commit 2c13dcb

Please sign in to comment.