Skip to content

Commit

Permalink
Feat: Re-implemented auto seal. Auto Seal is an optional parameter to…
Browse files Browse the repository at this point in the history
… the addSettlement method of balancing. The epoch n-value will be automatically sealed. Useful for meter readings - might be used with other balancing points in the future, but not implemented so far.
  • Loading branch information
zoernert committed Jan 19, 2024
1 parent 873388e commit 93efb97
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
24 changes: 15 additions & 9 deletions framework/services/balancing.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,12 @@ module.exports = {
} else {
await ctx.call("balance_settlements_active_model.insert",{entity:statement});
}
if(typeof ctx.params.autoseal !== 'undefined') {
ctx.call("balancing.seal",{
assetId:ctx.params.meterId,
epoch:ctx.params.epoch - (1*ctx.params.autoseal)
});
}
} catch(e) {
// in case of an exception the settlement needs to be handled manually.
// Handle manual settlement in case of an exception
Expand Down Expand Up @@ -334,7 +340,7 @@ module.exports = {
},
});
console.log("Query",{
"$or": [ { "from": ctx.params.assertId }, { "to": ctx.params.assetId}],
"$or": [ { "from": ctx.params.assetId }, { "to": ctx.params.assetId}],
epoch: ctx.params.epoch * 1
});
balance.upstream = await ctx.call("balancing.getUpstream", {assetId: ctx.params.assetId});
Expand Down Expand Up @@ -387,27 +393,27 @@ module.exports = {
}

let intermediateBalance = await ctx.call("balancing.unsealedBalance",ctx.params);
if(intermediateBalance.clearing.energy !== 0) {
if((intermediateBalance.energy !== 0)&&(intermediateBalance.clearing.energy !== 0)){
let statement = {
from: intermediateBalance.clearing.from,
to:intermediateBalance.clearing.to,
epoch: ctx.params.epoch * 1,
energy: intermediateBalance.clearing.energy,
label: ".end"
}
await ctx.call("balance_settlements_late_model.insert",{entity:statement});
await ctx.call("balance_settlements_active_model.insert",{entity:statement});
intermediateBalance = await ctx.call("balancing.unsealedBalance",ctx.params);
}
if(intermediateBalance.clearing.energy == 0) {
if((intermediateBalance.energy == 0)||(intermediateBalance.clearing.energy == 0)) {
let seal_content = {
assetId: ctx.params.assetId,
epoch: ctx.params.epoch * 1,
in: intermediateBalance.in,
out: intermediateBalance.out,
energy: intermediateBalance.energy,
upstream: intermediateBalance.upstream
upstream: intermediateBalance.upstream,
balance: intermediateBalance.in,
energy: intermediateBalance.upstreamenergy
}
const res = jwt.sign(seal_content, process.env.JWT_SECRET);
const signOptions = JSON.parse(process.env.JWT_OPTIONS);
const res = jwt.sign(seal_content, process.env.JWT_PRIVATEKEY,signOptions);
seal_content.seal = res;
await ctx.call("balances_sealed_model.insert",{entity:seal_content});
return seal_content;
Expand Down
1 change: 1 addition & 0 deletions framework/services/loadprofile.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ module.exports = {
await ctx.call("loadprofile_model.insert",{entity:existing});
}
// Forward to balancing (asynchronously)
ctx.params.autoseal = 1; // Auto seal for meter readings the previous epoch
ctx.call("balancing.addSettlement",ctx.params);
return;
}
Expand Down

0 comments on commit 93efb97

Please sign in to comment.