Skip to content

Commit

Permalink
checkpoint -- get import to work
Browse files Browse the repository at this point in the history
  • Loading branch information
jewei1997 committed Jul 12, 2024
1 parent 9f02321 commit 8d571df
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 23 deletions.
1 change: 1 addition & 0 deletions internal/consensus/replay.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ func (h *Handshaker) ReplayBlocks(
validatorSet := types.NewValidatorSet(validators)
nextVals := types.TM2PB.ValidatorUpdates(validatorSet)
pbParams := h.genDoc.ConsensusParams.ToProto()
// JEREMYFLAG: this is where InitChain is called
res, err := appClient.InitChain(ctx, &abci.RequestInitChain{
Time: h.genDoc.GenesisTime,
ChainId: h.genDoc.ChainID,
Expand Down
1 change: 1 addition & 0 deletions internal/proxy/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ func kill() error {
return p.Signal(syscall.SIGABRT)
}

// JEREMYFLAG: where InitChain gets called from replay ReplayBlocks
func (app *proxyClient) InitChain(ctx context.Context, req *types.RequestInitChain) (*types.ResponseInitChain, error) {
defer addTimeSample(app.metrics.MethodTiming.With("method", "init_chain", "type", "sync"))()
return app.client.InitChain(ctx, req)
Expand Down
45 changes: 23 additions & 22 deletions libs/bytes/bytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,26 +70,27 @@ func (bz HexBytes) Format(s fmt.State, verb rune) {
}
}

// This is the point of Bytes.
func (bz HexBytes) MarshalJSON() ([]byte, error) {
fmt.Println("In MarshalJSON")
s := strings.ToUpper(hex.EncodeToString(bz))
jbz := make([]byte, len(s)+2)
jbz[0] = '"'
copy(jbz[1:], s)
jbz[len(jbz)-1] = '"'
return jbz, nil
}
// // This is the point of Bytes.
// func (bz HexBytes) MarshalJSON() ([]byte, error) {
// fmt.Println("In MarshalJSON")
// s := strings.ToUpper(hex.EncodeToString(bz))
// jbz := make([]byte, len(s)+2)
// jbz[0] = '"'
// copy(jbz[1:], s)
// jbz[len(jbz)-1] = '"'
// return jbz, nil
// }

// This is the point of Bytes.
func (bz *HexBytes) UnmarshalJSON(data []byte) error {
if len(data) < 2 || data[0] != '"' || data[len(data)-1] != '"' {
return fmt.Errorf("invalid hex string: %s", data)
}
bz2, err := hex.DecodeString(string(data[1 : len(data)-1]))
if err != nil {
return err
}
*bz = bz2
return nil
}
// // This is the point of Bytes.
// func (bz *HexBytes) UnmarshalJSON(data []byte) error {
// fmt.Println("In UnmarshalJSON, data: ", string(data))
// if len(data) < 2 || data[0] != '"' || data[len(data)-1] != '"' {
// return fmt.Errorf("invalid hex string: %s", data)
// }
// bz2, err := hex.DecodeString(string(data[1 : len(data)-1]))
// if err != nil {
// return err
// }
// *bz = bz2
// return nil
// }
29 changes: 29 additions & 0 deletions libs/bytes/bytes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,35 @@ func TestMarshal(t *testing.T) {
assert.Equal(t, dataB, dataB2)
}

// // ValidateGenesis performs genesis state validation for the ibc module.
// func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncodingConfig, bz json.RawMessage) error {
// var gs types.GenesisState
// if err := cdc.UnmarshalJSON(bz, &gs); err != nil {
// return fmt.Errorf("failed to unmarshal %s genesis state: %w", host.ModuleName, err)
// }

// return gs.Validate()
// }

// Define a struct to match the JSON structure
type ValidatorsHash struct {
NextValidatorsHash HexBytes `json:"next_validators_hash"`
}

func TestUnmarshalCorruptedPOC(t *testing.T) {
jsonData := []byte(`{"next_validators_hash":"20021C2FB4B2DDFF6E8C484A2ED5862910E3AD7074FC6AD1C972AD34891AE3A4"}`)
expectedLength := 32
var vh ValidatorsHash
err := json.Unmarshal(jsonData, &vh)
fmt.Println("bz_: ", vh.NextValidatorsHash)
fmt.Printf("%x\n", vh.NextValidatorsHash)
if err != nil {
t.Fatalf("Error unmarshalling JSON: %v", err)
return
}
assert.Equal(t, expectedLength, len(vh.NextValidatorsHash))
}

// Test that the hex encoding works.
func TestJSONMarshal(t *testing.T) {
type TestStruct struct {
Expand Down
4 changes: 3 additions & 1 deletion node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ func makeNode(
tracerProviderOptions []trace.TracerProviderOption,
nodeMetrics *NodeMetrics,
) (service.Service, error) {

var cancel context.CancelFunc
ctx, cancel = context.WithCancel(ctx)

Expand All @@ -168,7 +167,9 @@ func makeNode(
return nil, combineCloseError(fmt.Errorf("error in genesis doc: %w", err), makeCloser(closers))
}

fmt.Println("In sei-tendermint node/node.go makeNode(), calling loadStateFromDBOrGenesisDocProvider()")
state, err := loadStateFromDBOrGenesisDocProvider(stateStore, genDoc)
fmt.Println("In sei-tendermint node/node.go makeNode(), after calling loadStateFromDBOrGenesisDocProvider(), state = ", state)
if err != nil {
return nil, combineCloseError(err, makeCloser(closers))
}
Expand Down Expand Up @@ -790,6 +791,7 @@ func loadStateFromDBOrGenesisDocProvider(stateStore sm.Store, genDoc *types.Gene
}

if state.IsEmpty() {
fmt.Println("In sei-tendermint loadStateFromDBOrGenesisDocProvider(), state is empty")
// 2. If it's not there, derive it from the genesis doc
state, err = sm.MakeGenesisState(genDoc)
if err != nil {
Expand Down

0 comments on commit 8d571df

Please sign in to comment.