Skip to content

Instantly share code, notes, and snippets.

View zeroFruit's full-sized avatar
🎯
Focusing

JooHyung Kim zeroFruit

🎯
Focusing
View GitHub Profile
@zeroFruit
zeroFruit / DefaultChannelPipeline.java
Created July 23, 2022 00:26
Channel concept & implementation— el Project (2)
public class DefaultChannelPipeline implements ChannelPipeline {
@Override
public ChannelPromise bind(SocketAddress localAddress) {
return this.tailContext.bind(localAddress);
}
@Override
public ChannelPromise bind(SocketAddress localAddress, ChannelPromise promise) {
return this.tailContext.bind(localAddress, promise);
@zeroFruit
zeroFruit / DefaultChannelPipeline.java
Created July 23, 2022 00:25
Channel concept & implementation— el Project (2)
public class DefaultChannelPipeline implements ChannelPipeline {
private final Channel channel;
private final HeadContext headContext;
private final TailContext tailContext;
public DefaultChannelPipeline(Channel channel) {
this.channel = channel;
this.tailContext = new TailContext(this);
this.headContext = new HeadContext(this);
@zeroFruit
zeroFruit / ChannelPipeline.java
Created July 23, 2022 00:23
Channel concept & implementation— el Project (2)
public interface ChannelPipeline
extends ChannelInboundInvoker, ChannelOutboundInvoker, Iterable<Entry<String, ChannelHandler>> {
/** Add handlers to its handler chain at the end. */
ChannelPipeline addLast(ChannelHandler... handlers);
/** Remove handler */
ChannelPipeline remove(ChannelHandler handler);
/** Returns channel it binds to. */
Channel channel();
@zeroFruit
zeroFruit / channel.java
Created July 23, 2022 00:16
Channel concept & implementation— el Project (2)
public interface Channel {
/** Returns the assigned {@link ChannelPipeline} */
ChannelPipeline pipeline();
/** Returns {@code true} if the {@link Channel} is open and may get active later */
boolean isOpen();
/** Returns {@code true} if the {@link Channel} is registered with an {@link ChannelEventLoop} */
boolean isRegistered();
@zeroFruit
zeroFruit / upgrade-proposal.sh
Created July 5, 2022 01:17
Cosmos Dev Series: Cosmos-SDK-based Blockchain Upgrade - upgrade-proposal.sh
#!/bin/bash
export SIMAPPD_V1_HOME=/path/to/simappd-v1
export SIMAPP_V1_BIN=$SIMAPPD_V1_HOME/cosmovisor/genesis/bin/cored
export DAEMON_HOME=/path/to/simappd-home
# Send SoftwareUpgrade proposal - Upgrade Name: v2.0.0
$SIMAPP_V1_BIN tx gov submit-proposal software-upgrade v2.0.0 --title v2.0.0 --description v2.0.0 --upgrade-height 40 --from validator1 --yes --home $DAEMON_HOME --chain-id app_9000-1
# Deposit for the proposal - Proposal ID: 1
@zeroFruit
zeroFruit / setup-node.sh
Created July 5, 2022 01:16
Cosmos Dev Series: Cosmos-SDK-based Blockchain Upgrade - setup-node.sh
#!/bin/bash
export DAEMON_NAME=simappd
export SIMAPPD_V1_HOME=/path/to/simappd-v1
export SIMAPPD_V2_HOME=/path/to/simappd-v2
export DAEMON_HOME=/path/to/simappd-home
# Tmp cosmovisor directory. In this directory, we are going to
# setup Cosmovisor directory structures and copy this directory
# into $DAEMON_HOME
@zeroFruit
zeroFruit / upgrades.go
Created July 5, 2022 01:14
Cosmos Dev Series: Cosmos-SDK-based Blockchain Upgrade - SimApp upgrade handler
package app // upgrades.go
func (app *App) setupUpgradeHandlers(
configurator module.Configurator,
...
) {
app.UpgradeKeeper.SetUpgradeHandler(
v2.UpgradeName,
v2.CreateUpgradeHandler(app.mm, configurator, ...),
)
@zeroFruit
zeroFruit / module.go
Last active July 5, 2022 01:14
Cosmos Dev Series: Cosmos-SDK-based Blockchain Upgrade - ModuleManager
func (m Manager) RunMigrations(ctx sdk.Context, cfg Configurator, fromVM VersionMap) (VersionMap, error) {
...
updatedVM := VersionMap{}
for _, moduleName := range modules {
module := m.Modules[moduleName]
fromVersion, exists := fromVM[moduleName]
toVersion := module.ConsensusVersion()
@zeroFruit
zeroFruit / module.go
Created July 5, 2022 01:11
Cosmos Dev Series: Cosmos-SDK-based Blockchain Upgrade - x/foo module
package foo
// RegisterServices registers a GRPC query service to respond to the
// module-specific GRPC queries.
func (am AppModule) RegisterServices(cfg module.Configurator) {
...
migrator := keeper.NewMigrator(am.keeper)
// register v1 -> v2 migration
if err := cfg.RegisterMigration(types.ModuleName, 1, migrator.Migrate1to2); err != nil {
@zeroFruit
zeroFruit / migrations.go
Created July 5, 2022 01:10
Cosmos Dev Series: Cosmos-SDK-based Blockchain Upgrade - x/foo migration impl
package v2 // migrations.go
func UpdateParams(ctx sdk.Context, paramStore *paramtypes.Subspace) error {
...
paramStore.Set(ctx, types.KeyValue, "foobar")
return nil
}
func MigrateStore(ctx sdk.Context, storeKey storetypes.StoreKey, cdc codec.BinaryCodec) error {