Skip to content
This repository has been archived by the owner on Jan 29, 2024. It is now read-only.

Commit

Permalink
epoch encoding for HAMT keys (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
adlrocha authored Mar 27, 2023
1 parent 0f630d6 commit 43436c9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
4 changes: 2 additions & 2 deletions gateway/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ func (st *State) GetSubnet(s adt.Store, id sdk.SubnetID) (*Subnet, bool, error)
return utils.GetOutOfHamt[Subnet](st.Subnets, s, id)
}

func (st *State) GetCheckpoints(s adt.Store, c abi.ChainEpoch) (*Checkpoint, bool, error) {
return utils.GetOutOfHamt[Checkpoint](st.Checkpoints, s, abi.UIntKey(uint64(c)))
func (st *State) GetCheckpoints(s adt.Store, e abi.ChainEpoch) (*Checkpoint, bool, error) {
return utils.GetOutOfHamt[Checkpoint](st.Checkpoints, s, sdk.EpochKey(e))
}

func (st *State) GetCrossMsgs(s adt.Store, cID cid.Cid) (*CrossMsgs, bool, error) {
Expand Down
15 changes: 15 additions & 0 deletions sdk/types.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package sdk

import (
"encoding/binary"

"github.com/filecoin-project/go-state-types/abi"
)

// Status defines the different states in which a subnet can be.
type Status int64

Expand All @@ -10,3 +16,12 @@ const (
Terminating
Killed
)

type EpochKey abi.ChainEpoch

func (k EpochKey) Key() string {
// varInt integer encoding
buf := make([]byte, binary.MaxVarintLen64)
n := binary.PutVarint(buf, int64(k))
return string(buf[:n])
}
2 changes: 1 addition & 1 deletion subnetactor/subnet-actor.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (st *State) GetStake(s adt.Store, id address.Address) (abi.TokenAmount, err
}

func (st *State) GetCheckpoint(s adt.Store, epoch abi.ChainEpoch) (*gateway.Checkpoint, bool, error) {
return utils.GetOutOfHamt[gateway.Checkpoint](st.Stake, s, abi.UIntKey(uint64(epoch)))
return utils.GetOutOfHamt[gateway.Checkpoint](st.Checkpoints, s, sdk.EpochKey(epoch))
}

func (st *State) GetCheckpointVotes(s adt.Store, checkCid cid.Cid) (*Votes, bool, error) {
Expand Down

0 comments on commit 43436c9

Please sign in to comment.