Skip to content

Commit

Permalink
re-write + test
Browse files Browse the repository at this point in the history
  • Loading branch information
Reecepbcups committed Oct 19, 2023
1 parent 9ee0d51 commit c4f9b9a
Show file tree
Hide file tree
Showing 72 changed files with 11,201 additions and 9,001 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ go.work
go.work.sum

# Depinject debug file
debug_container.dot
debug_container.dot

build/
22 changes: 22 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# make local-image
# docker run --rm -it poa:local q

FROM golang:1.21-alpine3.18 as builder

RUN set -eux; apk add --no-cache git libusb-dev linux-headers gcc musl-dev make go;

ENV GOPATH=""

COPY go.mod .
COPY go.sum .
RUN go mod download

COPY . .

RUN cd simapp && make build

FROM alpine:3.18

COPY --from=builder /go/simapp/build/* /bin/poad

ENTRYPOINT ["/bin/poad"]
18 changes: 14 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

DOCKER := $(shell which docker)

##################
### Build ####
##################
export GO111MODULE = on

####################
### Testing ####
####################

test:
@echo "--> Running tests"
Expand All @@ -14,7 +16,15 @@ test-integration:
@echo "--> Running integration tests"
cd integration; go test -v ./...

.PHONY: test test-integration
ictest-poa:
cd e2e && go clean -testcache && go test -race -v -run TestPOA .

###############################################################################
### Docker ###
###############################################################################

local-image:
docker build . -t poa:local

###################
### Protobuf ####
Expand Down
50 changes: 1 addition & 49 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,55 +8,7 @@ Describe specialized concepts and definitions used throughout the spec.

## State



Each Begin Block we iterate over the unconfirmed store and check if 2/3+ of validators have seen the same hash. If so, we finalize the attestation and add it to the finalized store.

```go
func (ave AttestationVoteExtension) ExtendVote(ctx sdk.Context, req *abci.RequestExtendVote) (*abci.ResponseExtendVote, error) {
// TODO: do we limit size of votes each block?
messagemax := ave.MaxVoteSize(ctx)
// []*CoveredHeader
observations := ave.Cache.CoveredHeaderObservations(ctx)
marshalledObservations := [][]byte{}
for _, observation := range observations {
bz, err := json.Marshal(observation)
if err != nil {
return nil, fmt.Errorf("failed to encode vote extension: %w", err)
}
if messagemax - len(bz) > 0 {
marshalledObservations = append(marshalledObservations, bz)
messagemax -= len(bz)
} else {
break
}
}
// turn the [][]byte into single []byte parsable json (i.e. add commas and [])
return &abci.ResponseExtendVote{VoteExtension: bz}, nil
}

// TODO: can we track covered chains and latest heights on the ve struct?
func (ave AttestationVoteExtension) VerifyVoteExtension(ctx sdk.Context, req *abci.RequestVerifyVoteExtension) (*abci.ResponseVerifyVoteExtension, error) {
var vote CoveredHeader
if err := json.Unmarshal(req.VoteExtension, &vote); err != nil {
return &abci.ResponseVerifyVoteExtension{Status: abci.ResponseVerifyVoteExtension_REJECT}, nil
}
// map[chain_id]height
chains := ave.CoveredChains(ctx)
switch {
case chains[req.ChainId] == nil:
return &abci.ResponseVerifyVoteExtension{Status: abci.ResponseVerifyVoteExtension_REJECT}, nil
case chains[req.ChainId] >= req.Height:
return &abci.ResponseVerifyVoteExtension{Status: abci.ResponseVerifyVoteExtension_REJECT}, nil
case len(ve.Data) != 1024:
return &abci.ResponseVerifyVoteExtension{Status: abci.ResponseVerifyVoteExtension_REJECT}, nil
}
if err := ave.Keeper.WriteHeaderAttestation(ctx, vote.HeaderAttestation(req.Validator)); err != nil {
return &abci.ResponseVerifyVoteExtension{Status: abci.ResponseVerifyVoteExtension_REJECT}, nil
}
return &abci.ResponseVerifyVoteExtension{Status: abci.ResponseVerifyVoteExtension_ACCEPT}, nil
}
```
Specify state stored with the module and the flow

## Messages

Expand Down
60 changes: 60 additions & 0 deletions ante/disable_staking.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package poaante

import (
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"

stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)

type MsgStakingFilterDecorator struct {
}

func NewPOAStakingFilterDecorator() MsgStakingFilterDecorator {
return MsgStakingFilterDecorator{}
}

// AnteHandle performs an AnteHandler check that returns an error if the tx contains a message that is blocked.
func (msfd MsgStakingFilterDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
currHeight := ctx.BlockHeight()
if currHeight <= 1 {
// allow GenTx to pass
return next(ctx, tx, simulate)
}

invalid, err := msfd.hasInvalidStakingMsg(tx.GetMsgs())
if err != nil {
return ctx, err
}

if invalid {
return ctx, fmt.Errorf("staking actions are now allowed on this authority chain")
}

return next(ctx, tx, simulate)
}

func (msfd MsgStakingFilterDecorator) hasInvalidStakingMsg(msgs []sdk.Msg) (bool, error) {
for _, msg := range msgs {
switch msg.(type) {
case *stakingtypes.MsgBeginRedelegate:
return true, nil
case *stakingtypes.MsgCancelUnbondingDelegation:
return true, nil
case *stakingtypes.MsgCreateValidator: // TODO:? wrap it to our own Message to allow & mint the needed token?
return true, nil
case *stakingtypes.MsgDelegate:
return true, nil
case *stakingtypes.MsgEditValidator: // TODO:?
return true, nil
case *stakingtypes.MsgUndelegate:
return true, nil
case *stakingtypes.MsgUpdateParams: // TODO: ? allow or wrap with isAdmin?
return true, nil
default:
return false, nil
}
}
return false, nil
}
104 changes: 82 additions & 22 deletions api/module/v1/module.pulsar.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c4f9b9a

Please sign in to comment.