Skip to content

Commit

Permalink
Remove TobinTax from DB
Browse files Browse the repository at this point in the history
  • Loading branch information
Eela Nagaraj committed Aug 23, 2023
1 parent 9a4322e commit c2c0e92
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 115 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ With a special focus on getting balance change operations, Celo Rosetta provides
the celo-blockchain rpc; such as:

- Gas Fee distribution
- Gold transfers (internal & external). Taking in account Tobin Tax
- CELO transfers (internal & external)
- Epoch Rewards Distribution
- LockedGold & Election Operations

Expand Down
4 changes: 0 additions & 4 deletions cmd/cli/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ var blockCmd = &cobra.Command{
block, fetcherErr := fetcher.BlockRetry(ctx, network, blockIdentifier)
utils.ExitOnFetcherError(fetcherErr)

// printBlockContext(block)

printBlockContext(block)
},
}
Expand All @@ -64,7 +62,6 @@ func printBlockContext(rosettabBlock *types.Block) {
gpm, err := db.GasPriceMinimumFor(ctx, blockNumber)
utils.ExitOnError(err)

tobinTax, err := db.TobinTaxFor(ctx, blockNumber)
utils.ExitOnError(err)

contractNames := []string{
Expand All @@ -88,7 +85,6 @@ func printBlockContext(rosettabBlock *types.Block) {
printTitle("Block Context")
w := tabwriter.NewWriter(os.Stdout, 20, 5, 3, ' ', tabwriter.TabIndent)
fmt.Fprintf(w, "GasPriceMinimum:\t%s\n", gpm)
fmt.Fprintf(w, "TobinTax:\t%s\n", tobinTax)
fmt.Fprintf(w, "Coinbase:\t%s\n", block.Coinbase().Hex())
if carbonOffsetPartner != common.ZeroAddress {
fmt.Fprintf(w, "CarbonOffsetPartner:\t%s\n", carbonOffsetPartner.Hex())
Expand Down
47 changes: 0 additions & 47 deletions db/sqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ type rosettaSqlDb struct {
updateLastBlockStmt *sql.Stmt
getRegistryAddressStmt *sql.Stmt
getGasPriceMinimumStmt *sql.Stmt
getTobinTaxStmt *sql.Stmt
getCarbonOffsetPartnerStmt *sql.Stmt
insertGasPriceMinimumStmt *sql.Stmt
insertTobinTaxStmt *sql.Stmt
insertRegistryAddressStmt *sql.Stmt
insertCarbonOffsetPartnerStmt *sql.Stmt
}
Expand All @@ -42,7 +40,6 @@ func initDatabase(db *sql.DB) error {
schema := []string{
"CREATE table IF NOT EXISTS registry (contract text, fromBlock integer, fromTx integer, address blob)",
"CREATE table IF NOT EXISTS gasPriceMinimum (fromBlock integer, val blob)",
"CREATE table IF NOT EXISTS tobinTax (fromBlock integer, val blob)",
"CREATE table IF NOT EXISTS carbonOffsetPartner (fromBlock integer, fromTx integer, address blob)",
"CREATE table IF NOT EXISTS stats (lastBlock integer not null DEFAULT 0)",
}
Expand Down Expand Up @@ -89,11 +86,6 @@ func NewSqliteDb(dbpath string) (*rosettaSqlDb, error) {
return nil, err
}

insertTobinTaxStmt, err := db.Prepare("INSERT INTO tobinTax (fromBlock, val) VALUES (?, ?)")
if err != nil {
return nil, err
}

insertRegistryAddressStmt, err := db.Prepare("INSERT INTO registry (contract, fromBlock, fromTx, address) VALUES (?, ?, ?, ?)")
if err != nil {
return nil, err
Expand Down Expand Up @@ -131,17 +123,6 @@ func NewSqliteDb(dbpath string) (*rosettaSqlDb, error) {
return nil, err
}

getTobinTaxStmt, err := db.Prepare(`
SELECT val
FROM tobinTax
WHERE fromBlock <= $1
ORDER BY fromblock DESC
LIMIT 1
`)
if err != nil {
return nil, err
}

getCarbonOffsetPartnerStmt, err := db.Prepare(`
SELECT address
FROM carbonOffsetPartner
Expand All @@ -159,10 +140,8 @@ func NewSqliteDb(dbpath string) (*rosettaSqlDb, error) {
updateLastBlockStmt: updateLastBlockStmt,
getRegistryAddressStmt: getRegistryAddressStmt,
getGasPriceMinimumStmt: getGasPriceMinimumStmt,
getTobinTaxStmt: getTobinTaxStmt,
getCarbonOffsetPartnerStmt: getCarbonOffsetPartnerStmt,
insertGasPriceMinimumStmt: insertGasPriceMinimumStmt,
insertTobinTaxStmt: insertTobinTaxStmt,
insertRegistryAddressStmt: insertRegistryAddressStmt,
insertCarbonOffsetPartnerStmt: insertCarbonOffsetPartnerStmt,
}, nil
Expand Down Expand Up @@ -214,23 +193,6 @@ func (cs *rosettaSqlDb) GasPriceMinimumFor(ctx context.Context, block *big.Int)
return new(big.Int).SetBytes(gpmBytes), nil
}

func (cs *rosettaSqlDb) TobinTaxFor(ctx context.Context, block *big.Int) (*big.Int, error) {
if err := cs.CheckBlockNumber(ctx, block); err != nil {
return nil, err
}

var tobinTaxNumerator []byte

if err := cs.getTobinTaxStmt.QueryRowContext(ctx, block.Uint64()).Scan(&tobinTaxNumerator); err != nil {
if err == sql.ErrNoRows {
return big.NewInt(0), nil
}
return nil, err
}

return new(big.Int).SetBytes(tobinTaxNumerator), nil
}

func (cs *rosettaSqlDb) RegistryAddressStartOf(ctx context.Context, block *big.Int, txIndex uint, contractName string) (common.Address, error) {
if err := cs.CheckBlockNumber(ctx, block); err != nil {
return common.ZeroAddress, err
Expand Down Expand Up @@ -318,15 +280,6 @@ func (cs *rosettaSqlDb) ApplyChanges(ctx context.Context, changeSet *BlockChange
}
}

if changeSet.TobinTax != nil {
if _, err = tx.StmtContext(ctx, cs.insertTobinTaxStmt).ExecContext(ctx, changeSet.BlockNumber.Int64(), changeSet.TobinTax.Bytes()); err != nil {
if rollbackErr := tx.Rollback(); rollbackErr != nil {
return rollbackErr
}
return err
}
}

if changeSet.CarbonOffsetPartnerChange.Address != common.ZeroAddress {
if _, err = tx.StmtContext(ctx, cs.insertCarbonOffsetPartnerStmt).ExecContext(ctx, changeSet.BlockNumber.Int64(), int64(changeSet.CarbonOffsetPartnerChange.TxIndex), changeSet.CarbonOffsetPartnerChange.Address); err != nil {
if rollbackErr := tx.Rollback(); rollbackErr != nil {
Expand Down
57 changes: 0 additions & 57 deletions db/sqlite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,63 +179,6 @@ func TestGasPriceMinimum(t *testing.T) {

}

func TestTobinTax(t *testing.T) {
RegisterTestingT(t)
ctx := context.Background()

celoDb, err := NewSqliteDb(":memory:")
Ω(err).ShouldNot(HaveOccurred())

err = celoDb.ApplyChanges(ctx, &BlockChangeSet{
BlockNumber: big.NewInt(10),
TobinTax: big.NewInt(50000),
})
Ω(err).ShouldNot(HaveOccurred())

err = celoDb.ApplyChanges(ctx, &BlockChangeSet{
BlockNumber: big.NewInt(15),
TobinTax: big.NewInt(100000),
})
Ω(err).ShouldNot(HaveOccurred())

var tobinTax *big.Int

t.Run("Before", func(t *testing.T) {
RegisterTestingT(t)
tobinTax, err = celoDb.TobinTaxFor(ctx, big.NewInt(9))
Ω(err).ShouldNot(HaveOccurred())
Ω(tobinTax.Uint64()).Should(Equal(uint64(0)))
})

t.Run("Same Block", func(t *testing.T) {
RegisterTestingT(t)
tobinTax, err = celoDb.TobinTaxFor(ctx, big.NewInt(10))
Ω(err).ShouldNot(HaveOccurred())
Ω(tobinTax.Uint64()).Should(Equal(uint64(50000)))
})

t.Run("After Block", func(t *testing.T) {
RegisterTestingT(t)
tobinTax, err = celoDb.TobinTaxFor(ctx, big.NewInt(11))
Ω(err).ShouldNot(HaveOccurred())
Ω(tobinTax.Uint64()).Should(Equal(uint64(50000)))
})

t.Run("On Next Change", func(t *testing.T) {
RegisterTestingT(t)
tobinTax, err = celoDb.TobinTaxFor(ctx, big.NewInt(15))
Ω(err).ShouldNot(HaveOccurred())
Ω(tobinTax.Uint64()).Should(Equal(uint64(100000)))
})

t.Run("After Last Persisted Change", func(t *testing.T) {
RegisterTestingT(t)
tobinTax, err = celoDb.TobinTaxFor(ctx, big.NewInt(17))
Ω(err).Should(Equal(ErrFutureBlock))
})

}

func TestGasPriceMinimum_VeryLargeNumber(t *testing.T) {
RegisterTestingT(t)
ctx := context.Background()
Expand Down
6 changes: 0 additions & 6 deletions db/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ type RosettaDBReader interface {
// in the following block.
GasPriceMinimumFor(ctx context.Context, block *big.Int) (*big.Int, error)

// TobinTaxFor returns the tobinTax applied to txs in that block.
// More specifically, it returns the numerator of the tobin tax.
// In case of no value, will return with fallbackValue which is 0
TobinTaxFor(ctx context.Context, block *big.Int) (*big.Int, error)

// RegistryAddressStartOf returns the address of the contract at the start of (block, tx)
// In case there's no record for that contract it will fail with ErrContractNotFound
RegistryAddressStartOf(ctx context.Context, block *big.Int, txIndex uint, contractName string) (common.Address, error)
Expand Down Expand Up @@ -79,7 +74,6 @@ type CarbonOffsetPartnerChange struct {
type BlockChangeSet struct {
BlockNumber *big.Int
GasPriceMinimum *big.Int
TobinTax *big.Int
RegistryChanges []RegistryChange
CarbonOffsetPartnerChange CarbonOffsetPartnerChange
}

0 comments on commit c2c0e92

Please sign in to comment.