diff --git a/docs/architecture/decisions/0006-uptime-hints.md b/docs/architecture/decisions/0006-uptime-hints.md new file mode 100644 index 000000000..dd6205f7e --- /dev/null +++ b/docs/architecture/decisions/0006-uptime-hints.md @@ -0,0 +1,23 @@ +# 1. Dynamic Cache + +Date: 2023-06-14 + +## Status + +Accepted + +## Context + +Use tfchain uptimeV2 instead of old deprecated v1 uptime + +## Decision + +The uptime v2 also give an `timestamp hint` which is the time when the node sent the report as per the node itself. The chain +will then accept the report if and only if the hint is in an acceptable range of the chain local timestamp. + +This is to prevent reports that have been buffered (delayed) on either sides of the client or the server from still getting processed +and causing inconsistency in the uptime report for that node. + +Now nodes that are going to use v2 will get an error if the report is too old (or in the future) + +## Consequences diff --git a/go.mod b/go.mod index 8ee40db8e..c8ebce7d3 100644 --- a/go.mod +++ b/go.mod @@ -42,7 +42,7 @@ require ( github.com/shirou/gopsutil v3.21.11+incompatible github.com/stretchr/testify v1.8.2 github.com/threefoldtech/0-fs v1.3.1-0.20201203163303-d963de9adea7 - github.com/threefoldtech/tfchain/clients/tfchain-client-go v0.0.0-20230509101146-8e43c43597cd + github.com/threefoldtech/tfchain/clients/tfchain-client-go v0.0.0-20230614080449-33e2dc5b38f2 github.com/threefoldtech/tfgrid-sdk-go/rmb-sdk-go v0.4.0 github.com/threefoldtech/zbus v1.0.1 github.com/tyler-smith/go-bip39 v1.1.0 diff --git a/go.sum b/go.sum index f6c244a36..fc658f676 100644 --- a/go.sum +++ b/go.sum @@ -535,6 +535,8 @@ github.com/threefoldtech/substrate-client v0.1.5 h1:yYmWaJCMoJO0ieaO6eu3vIK0ageh github.com/threefoldtech/substrate-client v0.1.5/go.mod h1:ys/GJLeLmNX8E36UFMeR0yZC5Lo4PufYtfwsVX8H/AM= github.com/threefoldtech/tfchain/clients/tfchain-client-go v0.0.0-20230509101146-8e43c43597cd h1:aermHEtCwO/gzn8OiwDzhvsBHOuxHFgHymcoFsRVNvQ= github.com/threefoldtech/tfchain/clients/tfchain-client-go v0.0.0-20230509101146-8e43c43597cd/go.mod h1:dtDKAPiUDxAwIkfHV7xcAFZcOm+xwNIuOI1MLFS+MeQ= +github.com/threefoldtech/tfchain/clients/tfchain-client-go v0.0.0-20230614080449-33e2dc5b38f2 h1:WZUNb8xu/Zxs9gwNDXL3FG2gwox1rgJudMCpsHCksJM= +github.com/threefoldtech/tfchain/clients/tfchain-client-go v0.0.0-20230614080449-33e2dc5b38f2/go.mod h1:dtDKAPiUDxAwIkfHV7xcAFZcOm+xwNIuOI1MLFS+MeQ= github.com/threefoldtech/tfgrid-sdk-go/rmb-sdk-go v0.2.0 h1:dUPLbUFYBTfsM31UpIyPVyv18kDMLczHYIINPK/mFKI= github.com/threefoldtech/tfgrid-sdk-go/rmb-sdk-go v0.2.0/go.mod h1:DDQ6ktnCli7z1+zpSR/j2twWwe6FUGxPO+WnEkRsnxw= github.com/threefoldtech/tfgrid-sdk-go/rmb-sdk-go v0.4.0 h1:fmCYshC+u0/1nqlu10TnZjZeywioXOSWpm6n8zPKgkI= diff --git a/pkg/power/uptime.go b/pkg/power/uptime.go index 06d3430af..c442d6f82 100644 --- a/pkg/power/uptime.go +++ b/pkg/power/uptime.go @@ -57,7 +57,7 @@ func (u *Uptime) SendNow() (types.Hash, error) { return types.Hash{}, errors.Wrap(err, "failed to get uptime") } - return sub.UpdateNodeUptime(u.id, uptime) + return sub.UpdateNodeUptimeV2(u.id, uptime, uint64(time.Now().Unix())) } func (u *Uptime) uptime(ctx context.Context) error {