Skip to content

Commit b2b8c2b

Browse files
author
abstrct
committed
Fixing refactoring bugs
1 parent 0deaf0e commit b2b8c2b

87 files changed

Lines changed: 157 additions & 113 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

x/structs/keeper/agreement_cache.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,20 @@ func (cache *AgreementCache) Commit() {
4646
cache.CC.k.logger.Info("Updating Agreement From Cache", "agreementId", cache.AgreementId)
4747

4848
if cache.Deleted {
49-
// TODO MAKE SURE THE INDEX IS DELETED
49+
cache.CC.k.RemoveAgreementProviderIndex(cache.CC.ctx, cache.GetProviderId(), cache.GetAgreementId())
50+
cache.CC.k.RemoveAgreementExpirationIndex(cache.CC.ctx, cache.GetEndBlock(), cache.GetAgreementId())
51+
if cache.EndBlockChanged && cache.PreviousEndBlock > 0 {
52+
cache.CC.k.RemoveAgreementExpirationIndex(cache.CC.ctx, cache.PreviousEndBlock, cache.GetAgreementId())
53+
}
5054
cache.CC.k.ClearAgreement(cache.CC.ctx, cache.AgreementId)
5155
} else {
5256
cache.CC.k.SetAgreement(cache.CC.ctx, cache.Agreement)
53-
}
54-
55-
if (cache.EndBlockChanged) {
56-
if cache.PreviousEndBlock > 0 {
57-
cache.CC.k.RemoveAgreementExpirationIndex(cache.CC.ctx, cache.PreviousEndBlock, cache.GetAgreementId())
58-
}
59-
cache.CC.k.SetAgreementExpirationIndex(cache.CC.ctx, cache.GetEndBlock(), cache.GetAgreementId())
57+
if (cache.EndBlockChanged) {
58+
if cache.PreviousEndBlock > 0 {
59+
cache.CC.k.RemoveAgreementExpirationIndex(cache.CC.ctx, cache.PreviousEndBlock, cache.GetAgreementId())
60+
}
61+
cache.CC.k.SetAgreementExpirationIndex(cache.CC.ctx, cache.GetEndBlock(), cache.GetAgreementId())
62+
}
6063
}
6164

6265
cache.Changed = false

x/structs/keeper/allocation_cache.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ func (cache *AllocationCache) SetSource(sourceObjectId string) (error) {
156156
}
157157

158158
cache.SetAllocationSourceObjectId(sourceObjectId)
159+
cache.CC.k.SetAllocationSourceIndex(cache.CC.ctx, sourceObjectId, cache.ID())
159160
return nil
160161
}
161162

x/structs/keeper/allocation_context.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ func (cc *CurrentContext) NewAllocation(
7272

7373
allocation.Id = GetObjectID(types.ObjectType_allocation, allocation.Index)
7474
allocation.Type = allocationType
75+
allocation.Creator = creator
76+
allocation.Controller = controller
7577

7678
allocationPowerAttributeId := GetGridAttributeIDByObjectId(types.GridAttributeType_power, allocation.Id)
7779
sourceCapacityAttributeId := GetGridAttributeIDByObjectId(types.GridAttributeType_capacity, sourceObjectId)

x/structs/keeper/current_context.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,29 @@ func (cc *CurrentContext) CommitAll() {
215215
planetAttributeCache.Commit()
216216
}
217217

218+
for _, agreementCache := range cc.agreements {
219+
agreementCache.Commit()
220+
}
221+
222+
for _, planetCache := range cc.planets {
223+
planetCache.Commit()
224+
}
225+
226+
for _, providerCache := range cc.providers {
227+
providerCache.Commit()
228+
}
218229

230+
for _, structCache := range cc.structs {
231+
structCache.Commit()
232+
}
233+
234+
for _, substationCache := range cc.substations {
235+
substationCache.Commit()
236+
}
237+
238+
for _, reactorCache := range cc.reactors {
239+
reactorCache.Commit()
240+
}
219241

220242
cc.committed = true
221243
/*

x/structs/keeper/grid_context.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,17 +131,18 @@ func (cc *CurrentContext) GridCascade() {
131131
capacityAttributeId := GetGridAttributeIDByObjectId(types.GridAttributeType_capacity, objectId)
132132

133133
for cc.GetGridAttribute(loadAttributeId) > cc.GetGridAttribute(capacityAttributeId) {
134+
if allocationPointer >= len(allocationList) {
135+
// Something is probably wrong here...
136+
cc.k.logger.Warn("Grid Queue problem", "objectId", objectId)
137+
break;
138+
}
139+
134140
cc.k.logger.Info("Grid Queue (Brownout)", "objectId", objectId, "load", cc.GetGridAttribute(loadAttributeId), "capacity", cc.GetGridAttribute(capacityAttributeId))
135141

136142
allocationList[allocationPointer].Destroy()
137143
cc.k.logger.Info("Grid Queue (Allocation Destroyed)", "allocationId", allocationList[allocationPointer].GetAllocationId())
138144

139145
allocationPointer++
140-
if allocationPointer >= len(allocationList) {
141-
// Something is probably wrong here...
142-
cc.k.logger.Warn("Grid Queue problem", "objectId", objectId)
143-
break;
144-
}
145146
}
146147
}
147148
}

x/structs/keeper/guild_membership_context.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ func (cc *CurrentContext) GetGuildMembershipApp(guildId string, playerId string)
1313

1414
cc.guildMembershipApps[appKey] = &GuildMembershipApplicationCache{
1515
GuildMembershipApplicationId: appKey,
16+
CC: cc,
1617
Changed: false,
1718
}
1819

x/structs/keeper/infusion.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func (k Keeper) GetInfusion(ctx context.Context, destinationId string, address s
5353
// GetInfusion returns a infusion from its id (destinationId-address)
5454
func (k Keeper) GetInfusionByID(ctx context.Context, infusionId string) (val types.Infusion, found bool) {
5555
infusionIdSplit := strings.Split(infusionId, "-")
56-
if len(infusionIdSplit) != 2 {
56+
if len(infusionIdSplit) != 3 {
5757
return types.Infusion{}, false
5858
}
5959
return k.GetInfusion(ctx, infusionIdSplit[0] + "-" + infusionIdSplit[1], infusionIdSplit[2])

x/structs/keeper/msg_server_address_register.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
func (k msgServer) AddressRegister(goCtx context.Context, msg *types.MsgAddressRegister) (*types.MsgAddressRegisterResponse, error) {
1616
ctx := sdk.UnwrapSDKContext(goCtx)
1717
cc := k.NewCurrentContext(ctx)
18-
defer cc.CommitAll()
1918

2019
// Add an Active Address record to the
2120
// indexer for UI requirements
@@ -113,5 +112,6 @@ func (k msgServer) AddressRegister(goCtx context.Context, msg *types.MsgAddressR
113112
}
114113

115114

115+
cc.CommitAll()
116116
return &types.MsgAddressRegisterResponse{}, nil
117117
}

x/structs/keeper/msg_server_address_revoke.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
func (k msgServer) AddressRevoke(goCtx context.Context, msg *types.MsgAddressRevoke) (*types.MsgAddressRevokeResponse, error) {
1212
ctx := sdk.UnwrapSDKContext(goCtx)
1313
cc := k.NewCurrentContext(ctx)
14-
defer cc.CommitAll()
1514

1615
// Add an Active Address record to the
1716
// indexer for UI requirements
@@ -64,5 +63,6 @@ func (k msgServer) AddressRevoke(goCtx context.Context, msg *types.MsgAddressRev
6463
// Clear Address Index
6564
k.RevokePlayerIndexForAddress(ctx, msg.Address, player.GetIndex())
6665

66+
cc.CommitAll()
6767
return &types.MsgAddressRevokeResponse{}, nil
6868
}

x/structs/keeper/msg_server_agreement_capacity_decrease.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
func (k msgServer) AgreementCapacityDecrease(goCtx context.Context, msg *types.MsgAgreementCapacityDecrease) (*types.MsgAgreementResponse, error) {
1111
ctx := sdk.UnwrapSDKContext(goCtx)
1212
cc := k.NewCurrentContext(ctx)
13-
defer cc.CommitAll()
1413

1514
// Add an Active Address record to the
1615
// indexer for UI requirements
@@ -32,5 +31,6 @@ func (k msgServer) AgreementCapacityDecrease(goCtx context.Context, msg *types.M
3231
// which increases duration
3332
agreement.CapacityDecrease(msg.CapacityDecrease)
3433

34+
cc.CommitAll()
3535
return &types.MsgAgreementResponse{}, nil
3636
}

0 commit comments

Comments
 (0)