Skip to content

Commit

Permalink
Fix: migration for teztnets
Browse files Browse the repository at this point in the history
  • Loading branch information
aopoltorzhicky committed Sep 7, 2023
1 parent f2d12be commit b337e03
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
11 changes: 9 additions & 2 deletions cmd/indexer/indexer/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ func (bi *BlockchainIndexer) handleBlock(ctx context.Context, block *Block) erro
return bi.StorageDB.DB.RunInTransaction(ctx,
func(tx *pg.Tx) error {

if block.Header.Protocol != bi.currentProtocol.Hash || (bi.Network == types.Mainnet && block.Header.Level == 1) {
if block.Header.Protocol != bi.currentProtocol.Hash || bi.needVestingMigration(block.Header.Level) {
logger.Info().Str("network", bi.Network.String()).Msgf("New protocol detected: %s -> %s", bi.currentProtocol.Hash, block.Header.Protocol)

if err := bi.migrate(ctx, block.Header, tx); err != nil {
Expand Down Expand Up @@ -417,7 +417,7 @@ func (bi *BlockchainIndexer) migrate(ctx context.Context, head noderpc.Header, t
}
}

if bi.Network == types.Mainnet && head.Level == 1 {
if bi.needVestingMigration(head.Level) {
if err := bi.vestingMigration(ctx, head, tx); err != nil {
return err
}
Expand All @@ -443,6 +443,13 @@ func (bi *BlockchainIndexer) migrate(ctx context.Context, head noderpc.Header, t
return nil
}

func (bi *BlockchainIndexer) needVestingMigration(level int64) bool {
return (bi.Network == types.Mainnet ||
bi.Network == types.Dailynet ||
bi.Network == types.Mondaynet) &&
level == 1
}

func (bi *BlockchainIndexer) implicitMigration(ctx context.Context, block *Block, protocol protocol.Protocol, store parsers.Store) error {
if block == nil || block.Metadata == nil {
return nil
Expand Down
1 change: 1 addition & 0 deletions configs/testnets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ storage:
password: ${POSTGRES_PASSWORD}
sslmode: disable
timeout: 10
log_queries: ${POSTGRES_LOG_QUERIES:-false}

sentry:
environment: development
Expand Down
19 changes: 16 additions & 3 deletions internal/noderpc/responses.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,22 @@ type ContractData struct {
Balance int64 `json:"balance,string"`
Counter int64 `json:"counter,string"`
Manager string `json:"manager"`
Delegate struct {
Value string `json:"value"`
} `json:"delegate"`
Delegate Delegate `json:"delegate"`
}

type Delegate struct {
Value string `json:"value"`
}

func (d *Delegate) UnmarshalJSON(data []byte) error {
var s string
if err := json.Unmarshal(data, &s); err == nil {
d.Value = s
return nil
}

type buf Delegate
return json.Unmarshal(data, (*buf)(d))
}

// OperationGroup -
Expand Down
4 changes: 4 additions & 0 deletions internal/parsers/migrations/jakarta.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ func NewJakarta() *Jakarta {
"KT1DrJV8vhkdLEj76h1H9Q4irZDqAkMPo1Qf": {},
"KT1D68BvUm9N1fcq6uaZnyZvmBkBvj9biyPu": {},
"KT1CT7S2b9hXNRxRrEcany9sak1qe4aaFAZJ": {},
"KT1FHqsvc7vRS3u54L66DdMX4gb6QKqxJ1JW": {},
"KT1QwBaLj5TRaGU3qkU4ZKKQ5mvNvyyzGBFv": {},
"KT1TxqZ8QtKvLu3V3JH7Gx58n7Co8pgtpQU5": {},
"KT1VqarPDicMFn1ejmQqqshUkUXTCTXwmkCN": {},
},
}
}
Expand Down

0 comments on commit b337e03

Please sign in to comment.