Skip to content

Commit

Permalink
nit
Browse files Browse the repository at this point in the history
Signed-off-by: Joshua Kim <[email protected]>
  • Loading branch information
joshua-kim committed Dec 2, 2024
1 parent d8330d0 commit 20eae56
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 256 deletions.
171 changes: 0 additions & 171 deletions x/dsmr/certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import (
"github.com/ava-labs/avalanchego/utils/units"
"github.com/ava-labs/avalanchego/utils/wrappers"
"github.com/ava-labs/avalanchego/vms/platformvm/warp"
"github.com/ava-labs/avalanchego/vms/platformvm/warp/payload"

"github.com/ava-labs/hypersdk/codec"

acodec "github.com/ava-labs/avalanchego/codec"
Expand All @@ -34,7 +32,6 @@ func init() {
lc := linearcodec.NewDefault()

err := errors.Join(
lc.RegisterType(&WarpChunkCertificate{}),
Codec.RegisterCodec(CodecVersion, lc),
)
if err != nil {
Expand Down Expand Up @@ -98,171 +95,3 @@ func (c *ChunkCertificate) Verify(

return nil
}

type WarpChunkPayload struct {
ChunkID ids.ID `serialize:"true"`
Slot int64 `serialize:"true"`

bytes []byte
}

func NewWarpChunkPayload(chunkID ids.ID, slot int64) (*WarpChunkPayload, error) {
payload := &WarpChunkPayload{
ChunkID: chunkID,
Slot: slot,
}

bytes, err := Codec.Marshal(CodecVersion, payload)
if err != nil {
return nil, err
}
payload.bytes = bytes
return payload, nil
}

func ParseWarpChunkPayload(b []byte) (*WarpChunkPayload, error) {
warpChunkPayload := &WarpChunkPayload{bytes: b}
if _, err := Codec.Unmarshal(warpChunkPayload.bytes, warpChunkPayload); err != nil {
return nil, err
}
return warpChunkPayload, nil
}

func (p *WarpChunkPayload) Bytes() []byte { return p.bytes }

type UnsignedWarpChunkCertificate struct {
UnsignedMessage *warp.UnsignedMessage
AddressedCall *payload.AddressedCall
Payload *WarpChunkPayload
}

func NewUnsignedWarpChunkCertificate(
networkID uint32,
sourceChainID ids.ID,
chunkID ids.ID,
slot int64,
) (*UnsignedWarpChunkCertificate, error) {
warpChunkPayload, err := NewWarpChunkPayload(chunkID, slot)
if err != nil {
return nil, err
}

addressedCall, err := payload.NewAddressedCall([]byte{}, warpChunkPayload.Bytes())
if err != nil {
return nil, err
}
unsignedMessage, err := warp.NewUnsignedMessage(
networkID,
sourceChainID,
addressedCall.Bytes(),
)
if err != nil {
return nil, err
}
return &UnsignedWarpChunkCertificate{
UnsignedMessage: unsignedMessage,
AddressedCall: addressedCall,
Payload: warpChunkPayload,
}, nil
}

func ParseUnsignedWarpChunkCertificate(b []byte) (*UnsignedWarpChunkCertificate, error) {
unsignedMessage, err := warp.ParseUnsignedMessage(b)
if err != nil {
return nil, err
}

addressedCall, err := payload.ParseAddressedCall(unsignedMessage.Payload)
if err != nil {
return nil, err
}
if len(addressedCall.SourceAddress) != 0 {
return nil, fmt.Errorf("failed to parse system source address: %x", addressedCall.SourceAddress)
}

warpChunkPayload, err := ParseWarpChunkPayload(addressedCall.Payload)
if err != nil {
return nil, err
}

return &UnsignedWarpChunkCertificate{
UnsignedMessage: unsignedMessage,
AddressedCall: addressedCall,
Payload: warpChunkPayload,
}, nil
}

func (c *UnsignedWarpChunkCertificate) ChunkID() ids.ID {
return c.Payload.ChunkID
}

func (c *UnsignedWarpChunkCertificate) Slot() int64 {
return c.Payload.Slot
}

func (c *UnsignedWarpChunkCertificate) Bytes() []byte { return c.UnsignedMessage.Bytes() }

type WarpChunkCertificate struct {
UnsignedCertificate *UnsignedWarpChunkCertificate
Message *warp.Message
}

func NewWarpChunkCertificate(
unsignedCertificate *UnsignedWarpChunkCertificate,
signature warp.Signature,
) (*WarpChunkCertificate, error) {
msg, err := warp.NewMessage(unsignedCertificate.UnsignedMessage, signature)
if err != nil {
return nil, err
}
return &WarpChunkCertificate{
UnsignedCertificate: unsignedCertificate,
Message: msg,
}, nil
}

func ParseWarpChunkCertificate(b []byte) (*WarpChunkCertificate, error) {
msg, err := warp.ParseMessage(b)
if err != nil {
return nil, err
}

cert, err := ParseUnsignedWarpChunkCertificate(msg.UnsignedMessage.Bytes())
if err != nil {
return nil, err
}

return &WarpChunkCertificate{
UnsignedCertificate: cert,
Message: msg,
}, nil
}

func (c *WarpChunkCertificate) GetChunkID() ids.ID { return c.UnsignedCertificate.ChunkID() }

func (c *WarpChunkCertificate) GetSlot() int64 { return c.UnsignedCertificate.Slot() }

func (c *WarpChunkCertificate) Bytes() []byte { return c.Message.Bytes() }

type WarpChunkVerificationContext struct {
NetworkID uint32
PChainState validators.State
PChainHeight uint64
QuorumNum uint64
QuorumDen uint64
}

func (c *WarpChunkCertificate) Verify(
ctx context.Context,
verificationContext WarpChunkVerificationContext,
) error {
return c.Message.Signature.Verify(
ctx,
c.UnsignedCertificate.UnsignedMessage,
verificationContext.NetworkID,
verificationContext.PChainState,
verificationContext.PChainHeight,
verificationContext.QuorumNum,
verificationContext.QuorumDen,
)
}
85 changes: 0 additions & 85 deletions x/dsmr/certificate_test.go

This file was deleted.

0 comments on commit 20eae56

Please sign in to comment.