Skip to content

Commit

Permalink
Set last Arweave block
Browse files Browse the repository at this point in the history
  • Loading branch information
szynwelski committed Jan 10, 2024
1 parent bf23649 commit e077370
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 17 deletions.
1 change: 1 addition & 0 deletions cmd/sequencerd/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func initCometBFTConfig() *cmtcfg.Config {
// cfg.P2P.MaxNumInboundPeers = 100
// cfg.P2P.MaxNumOutboundPeers = 40

cfg.P2P.PexReactor = false
return cfg
}

Expand Down
52 changes: 37 additions & 15 deletions x/sequencer/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,13 @@ func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *r
type AppModule struct {
AppModuleBasic

keeper keeper.Keeper
accountKeeper types.AccountKeeper
bankKeeper types.BankKeeper
genesisLoader GenesisLoader
blockInteractions *ante.BlockInteractions
keeper keeper.Keeper
accountKeeper types.AccountKeeper
bankKeeper types.BankKeeper
genesisLoader GenesisLoader
blockInteractions *ante.BlockInteractions
arweaveErrorsCounter *controller.ArweaveBlockErrorsCounter
arweaveBlocksController controller.ArweaveBlocksController
}

func NewAppModule(
Expand All @@ -111,14 +113,18 @@ func NewAppModule(
bankKeeper types.BankKeeper,
genesisLoader GenesisLoader,
blockInteractions *ante.BlockInteractions,
arweaveBlocksController controller.ArweaveBlocksController,
arweaveErrorsCounter *controller.ArweaveBlockErrorsCounter,
) AppModule {
return AppModule{
AppModuleBasic: NewAppModuleBasic(cdc),
keeper: keeper,
accountKeeper: accountKeeper,
bankKeeper: bankKeeper,
genesisLoader: genesisLoader,
blockInteractions: blockInteractions,
AppModuleBasic: NewAppModuleBasic(cdc),
keeper: keeper,
accountKeeper: accountKeeper,
bankKeeper: bankKeeper,
genesisLoader: genesisLoader,
blockInteractions: blockInteractions,
arweaveBlocksController: arweaveBlocksController,
arweaveErrorsCounter: arweaveErrorsCounter,
}
}

Expand Down Expand Up @@ -154,15 +160,30 @@ func (AppModule) ConsensusVersion() uint64 { return 1 }
// BeginBlock contains the logic that is automatically triggered at the beginning of each block.
// The begin block implementation is optional.
func (am AppModule) BeginBlock(_ context.Context) error {
am.blockInteractions.NewBlock()
if am.arweaveErrorsCounter != nil {
am.arweaveErrorsCounter.Reset()
}
return nil
}

// EndBlock contains the logic that is automatically triggered at the end of each block.
// The end block implementation is optional.
func (am AppModule) EndBlock(_ context.Context) error {
func (am AppModule) EndBlock(ctx context.Context) error {
am.startOrUpdateArweaveBlocksController(ctx)
return nil
}

// Starts the controller to fetch next Arweave blocks
// or remove blocks that have already been added to the blockchain
func (am AppModule) startOrUpdateArweaveBlocksController(ctx context.Context) {
if am.arweaveBlocksController == nil {
return
}
lastArweaveBlock := am.keeper.MustGetLastArweaveBlock(ctx)
am.arweaveBlocksController.SetLastAcceptedBlock(lastArweaveBlock.ArweaveBlock)
}

// IsOnePerModuleType implements the depinject.OnePerModuleType interface.
func (am AppModule) IsOnePerModuleType() {}

Expand Down Expand Up @@ -216,17 +237,18 @@ func ProvideModule(in ModuleInputs) ModuleOutputs {
in.Logger,
authority.String(),
)
abp := NewArweaveBlockProvider(&k, in.ArweaveBlocksController, in.GenesisLoader)
abec := controller.NewArweaveBlockErrorsCounter(in.ArweaveBlocksController, k, in.Logger)
m := NewAppModule(
in.Cdc,
k,
in.AccountKeeper,
in.BankKeeper,
in.GenesisLoader,
in.BlockInteractions,
in.ArweaveBlocksController,
abec,
)

abp := NewArweaveBlockProvider(&k, in.ArweaveBlocksController, in.GenesisLoader)
abec := controller.NewArweaveBlockErrorsCounter(in.ArweaveBlocksController, k, in.Logger)

return ModuleOutputs{SequencerKeeper: k, Module: m, ArweaveBlockProvider: abp, ArweaveBlockErrorsCounter: abec}
}
2 changes: 1 addition & 1 deletion x/sequencer/proposal/tx_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (

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

"github.com/warp-contracts/sequencer/x/sequencer/types"
"github.com/warp-contracts/sequencer/x/sequencer/module"
"github.com/warp-contracts/sequencer/x/sequencer/types"
)

// It validates the transaction and provides two methods for validation:
Expand Down
5 changes: 4 additions & 1 deletion x/sequencer/types/message_arweave_block.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package types

import (
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/reflect/protoreflect"

"cosmossdk.io/errors"
Expand Down Expand Up @@ -33,6 +34,8 @@ func (msg *MsgArweaveBlock) ValidateBasic() error {
func ProvideMsgArweaveBlockGetSingers() signing.CustomGetSigner {
return signing.CustomGetSigner{
MsgType: protoreflect.FullName("sequencer.sequencer.MsgArweaveBlock"),
Fn: nil,
Fn: func(msg proto.Message) ([][]byte, error) {
return [][]byte{{0x0}}, nil
},
}
}

0 comments on commit e077370

Please sign in to comment.