Commit 68e0b591 authored by Ralph Pichler's avatar Ralph Pichler Committed by GitHub

feat: new postage contracts (#1781)

parent d4fcf466
...@@ -62,7 +62,6 @@ const ( ...@@ -62,7 +62,6 @@ const (
optionNameTransactionHash = "transaction" optionNameTransactionHash = "transaction"
optionNameFullNode = "full-node" optionNameFullNode = "full-node"
optionNamePostageContractAddress = "postage-stamp-address" optionNamePostageContractAddress = "postage-stamp-address"
optionNamePriceOracleAddress = "price-oracle-address"
optionNameBlockTime = "block-time" optionNameBlockTime = "block-time"
) )
...@@ -233,7 +232,6 @@ func (c *command) setAllFlags(cmd *cobra.Command) { ...@@ -233,7 +232,6 @@ func (c *command) setAllFlags(cmd *cobra.Command) {
cmd.Flags().Bool(optionNameSwapEnable, true, "enable swap") cmd.Flags().Bool(optionNameSwapEnable, true, "enable swap")
cmd.Flags().Bool(optionNameFullNode, false, "cause the node to start in full mode") cmd.Flags().Bool(optionNameFullNode, false, "cause the node to start in full mode")
cmd.Flags().String(optionNamePostageContractAddress, "", "postage stamp contract address") cmd.Flags().String(optionNamePostageContractAddress, "", "postage stamp contract address")
cmd.Flags().String(optionNamePriceOracleAddress, "", "price oracle address")
cmd.Flags().String(optionNameTransactionHash, "", "proof-of-identity transaction hash") cmd.Flags().String(optionNameTransactionHash, "", "proof-of-identity transaction hash")
cmd.Flags().Uint64(optionNameBlockTime, 15, "chain block time") cmd.Flags().Uint64(optionNameBlockTime, 15, "chain block time")
} }
......
...@@ -152,7 +152,6 @@ Welcome to the Swarm.... Bzzz Bzzzz Bzzzz ...@@ -152,7 +152,6 @@ Welcome to the Swarm.... Bzzz Bzzzz Bzzzz
FullNodeMode: fullNode, FullNodeMode: fullNode,
Transaction: c.config.GetString(optionNameTransactionHash), Transaction: c.config.GetString(optionNameTransactionHash),
PostageContractAddress: c.config.GetString(optionNamePostageContractAddress), PostageContractAddress: c.config.GetString(optionNamePostageContractAddress),
PriceOracleAddress: c.config.GetString(optionNamePriceOracleAddress),
BlockTime: c.config.GetUint64(optionNameBlockTime), BlockTime: c.config.GetUint64(optionNameBlockTime),
}) })
if err != nil { if err != nil {
......
...@@ -8,7 +8,7 @@ require ( ...@@ -8,7 +8,7 @@ require (
github.com/coreos/go-semver v0.3.0 github.com/coreos/go-semver v0.3.0
github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c // indirect github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c // indirect
github.com/ethereum/go-ethereum v1.9.23 github.com/ethereum/go-ethereum v1.9.23
github.com/ethersphere/go-storage-incentives-abi v0.1.0 github.com/ethersphere/go-storage-incentives-abi v0.2.0
github.com/ethersphere/go-sw3-abi v0.4.0 github.com/ethersphere/go-sw3-abi v0.4.0
github.com/ethersphere/langos v1.0.0 github.com/ethersphere/langos v1.0.0
github.com/gogo/protobuf v1.3.1 github.com/gogo/protobuf v1.3.1
......
...@@ -160,8 +160,8 @@ github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1m ...@@ -160,8 +160,8 @@ github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1m
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/ethereum/go-ethereum v1.9.23 h1:SIKhg/z4Q7AbvqcxuPYvMxf36che/Rq/Pp0IdYEkbtw= github.com/ethereum/go-ethereum v1.9.23 h1:SIKhg/z4Q7AbvqcxuPYvMxf36che/Rq/Pp0IdYEkbtw=
github.com/ethereum/go-ethereum v1.9.23/go.mod h1:JIfVb6esrqALTExdz9hRYvrP0xBDf6wCncIu1hNwHpM= github.com/ethereum/go-ethereum v1.9.23/go.mod h1:JIfVb6esrqALTExdz9hRYvrP0xBDf6wCncIu1hNwHpM=
github.com/ethersphere/go-storage-incentives-abi v0.1.0 h1:yxNME3q5dha/pUtIYB07DALhhQjd3+uYhGLFqKMXVyg= github.com/ethersphere/go-storage-incentives-abi v0.2.0 h1:TZ15auzGsdzuzUR2b5dLAMpFixorb4uKUDGF0QnVmmU=
github.com/ethersphere/go-storage-incentives-abi v0.1.0/go.mod h1:SXvJVtM4sEsaSKD0jc1ClpDLw8ErPoROZDme4Wrc/Nc= github.com/ethersphere/go-storage-incentives-abi v0.2.0/go.mod h1:SXvJVtM4sEsaSKD0jc1ClpDLw8ErPoROZDme4Wrc/Nc=
github.com/ethersphere/go-sw3-abi v0.4.0 h1:T3ANY+ktWrPAwe2U0tZi+DILpkHzto5ym/XwV/Bbz8g= github.com/ethersphere/go-sw3-abi v0.4.0 h1:T3ANY+ktWrPAwe2U0tZi+DILpkHzto5ym/XwV/Bbz8g=
github.com/ethersphere/go-sw3-abi v0.4.0/go.mod h1:BmpsvJ8idQZdYEtWnvxA8POYQ8Rl/NhyCdF0zLMOOJU= github.com/ethersphere/go-sw3-abi v0.4.0/go.mod h1:BmpsvJ8idQZdYEtWnvxA8POYQ8Rl/NhyCdF0zLMOOJU=
github.com/ethersphere/langos v1.0.0 h1:NBtNKzXTTRSue95uOlzPN4py7Aofs0xWPzyj4AI1Vcc= github.com/ethersphere/langos v1.0.0 h1:NBtNKzXTTRSue95uOlzPN4py7Aofs0xWPzyj4AI1Vcc=
......
...@@ -346,27 +346,20 @@ func NewBee(addr string, swarmAddress swarm.Address, publicKey ecdsa.PublicKey, ...@@ -346,27 +346,20 @@ func NewBee(addr string, swarmAddress swarm.Address, publicKey ecdsa.PublicKey,
var postageSyncStart uint64 = 0 var postageSyncStart uint64 = 0
if !o.Standalone { if !o.Standalone {
postageContractAddress, priceOracleAddress, startBlock, found := listener.DiscoverAddresses(chainID) postageContractAddress, startBlock, found := listener.DiscoverAddresses(chainID)
if o.PostageContractAddress != "" { if o.PostageContractAddress != "" {
if !common.IsHexAddress(o.PostageContractAddress) { if !common.IsHexAddress(o.PostageContractAddress) {
return nil, errors.New("malformed postage stamp address") return nil, errors.New("malformed postage stamp address")
} }
postageContractAddress = common.HexToAddress(o.PostageContractAddress) postageContractAddress = common.HexToAddress(o.PostageContractAddress)
} } else if !found {
if o.PriceOracleAddress != "" {
if !common.IsHexAddress(o.PriceOracleAddress) {
return nil, errors.New("malformed price oracle address")
}
priceOracleAddress = common.HexToAddress(o.PriceOracleAddress)
}
if (o.PostageContractAddress == "" || o.PriceOracleAddress == "") && !found {
return nil, errors.New("no known postage stamp addresses for this network") return nil, errors.New("no known postage stamp addresses for this network")
} }
if found { if found {
postageSyncStart = startBlock postageSyncStart = startBlock
} }
eventListener := listener.New(logger, swapBackend, postageContractAddress, priceOracleAddress, o.BlockTime) eventListener := listener.New(logger, swapBackend, postageContractAddress, o.BlockTime)
b.listenerCloser = eventListener b.listenerCloser = eventListener
batchSvc = batchservice.New(batchStore, logger, eventListener) batchSvc = batchservice.New(batchStore, logger, eventListener)
......
...@@ -6,7 +6,6 @@ package listener ...@@ -6,7 +6,6 @@ package listener
var ( var (
PostageStampABI = postageStampABI PostageStampABI = postageStampABI
PriceOracleABI = priceOracleABI
BatchCreatedTopic = batchCreatedTopic BatchCreatedTopic = batchCreatedTopic
BatchTopupTopic = batchTopupTopic BatchTopupTopic = batchTopupTopic
......
...@@ -30,16 +30,15 @@ const ( ...@@ -30,16 +30,15 @@ const (
) )
var ( var (
postageStampABI = parseABI(postageabi.PostageStampABIv0_1_0) postageStampABI = parseABI(postageabi.PostageStampABIv0_2_0)
priceOracleABI = parseABI(postageabi.PriceOracleABIv0_1_0)
// batchCreatedTopic is the postage contract's batch created event topic // batchCreatedTopic is the postage contract's batch created event topic
batchCreatedTopic = postageStampABI.Events["BatchCreated"].ID batchCreatedTopic = postageStampABI.Events["BatchCreated"].ID
// batchTopupTopic is the postage contract's batch topup event topic // batchTopupTopic is the postage contract's batch topup event topic
batchTopupTopic = postageStampABI.Events["BatchTopUp"].ID batchTopupTopic = postageStampABI.Events["BatchTopUp"].ID
// batchDepthIncreaseTopic is the postage contract's batch dilution event topic // batchDepthIncreaseTopic is the postage contract's batch dilution event topic
batchDepthIncreaseTopic = postageStampABI.Events["BatchDepthIncrease"].ID batchDepthIncreaseTopic = postageStampABI.Events["BatchDepthIncrease"].ID
// priceUpdateTopic is the price oracle's price update event topic // priceUpdateTopic is the postage contract's price update event topic
priceUpdateTopic = priceOracleABI.Events["PriceUpdate"].ID priceUpdateTopic = postageStampABI.Events["PriceUpdate"].ID
) )
type BlockHeightContractFilterer interface { type BlockHeightContractFilterer interface {
...@@ -53,7 +52,6 @@ type listener struct { ...@@ -53,7 +52,6 @@ type listener struct {
blockTime uint64 blockTime uint64
postageStampAddress common.Address postageStampAddress common.Address
priceOracleAddress common.Address
quit chan struct{} quit chan struct{}
wg sync.WaitGroup wg sync.WaitGroup
} }
...@@ -61,17 +59,14 @@ type listener struct { ...@@ -61,17 +59,14 @@ type listener struct {
func New( func New(
logger logging.Logger, logger logging.Logger,
ev BlockHeightContractFilterer, ev BlockHeightContractFilterer,
postageStampAddress, postageStampAddress common.Address,
priceOracleAddress common.Address,
blockTime uint64, blockTime uint64,
) postage.Listener { ) postage.Listener {
return &listener{ return &listener{
logger: logger, logger: logger,
ev: ev, ev: ev,
blockTime: blockTime, blockTime: blockTime,
postageStampAddress: postageStampAddress, postageStampAddress: postageStampAddress,
priceOracleAddress: priceOracleAddress,
quit: make(chan struct{}), quit: make(chan struct{}),
} }
} }
...@@ -82,7 +77,6 @@ func (l *listener) filterQuery(from, to *big.Int) ethereum.FilterQuery { ...@@ -82,7 +77,6 @@ func (l *listener) filterQuery(from, to *big.Int) ethereum.FilterQuery {
ToBlock: to, ToBlock: to,
Addresses: []common.Address{ Addresses: []common.Address{
l.postageStampAddress, l.postageStampAddress,
l.priceOracleAddress,
}, },
Topics: [][]common.Hash{ Topics: [][]common.Hash{
{ {
...@@ -132,7 +126,7 @@ func (l *listener) processEvent(e types.Log, updater postage.EventUpdater) error ...@@ -132,7 +126,7 @@ func (l *listener) processEvent(e types.Log, updater postage.EventUpdater) error
) )
case priceUpdateTopic: case priceUpdateTopic:
c := &priceUpdateEvent{} c := &priceUpdateEvent{}
err := transaction.ParseEvent(&priceOracleABI, "PriceUpdate", c, e) err := transaction.ParseEvent(&postageStampABI, "PriceUpdate", c, e)
if err != nil { if err != nil {
return err return err
} }
...@@ -210,6 +204,11 @@ func (l *listener) Listen(from uint64, updater postage.EventUpdater) <-chan stru ...@@ -210,6 +204,11 @@ func (l *listener) Listen(from uint64, updater postage.EventUpdater) <-chan stru
} }
} }
err = updater.UpdateBlockNumber(to)
if err != nil {
return err
}
from = to + 1 from = to + 1
} }
} }
...@@ -274,16 +273,15 @@ type priceUpdateEvent struct { ...@@ -274,16 +273,15 @@ type priceUpdateEvent struct {
} }
var ( var (
GoerliPostageStampContractAddress = common.HexToAddress("0xF7a041E7e2B79ccA1975852Eb6D4c6cE52986b4a") GoerliPostageStampContractAddress = common.HexToAddress("0xB3B7f2eD97B735893316aEeA849235de5e8972a2")
GoerliPriceOracleContractAddress = common.HexToAddress("0x1044534090de6f4014ece6d036C699130Bd5Df43") GoerliStartBlock = uint64(4818979)
GoerliStartBlock = uint64(4247101)
) )
// DiscoverAddresses returns the canonical contracts for this chainID // DiscoverAddresses returns the canonical contracts for this chainID
func DiscoverAddresses(chainID int64) (postageStamp, priceOracle common.Address, startBlock uint64, found bool) { func DiscoverAddresses(chainID int64) (postageStamp common.Address, startBlock uint64, found bool) {
if chainID == 5 { if chainID == 5 {
// goerli // goerli
return GoerliPostageStampContractAddress, GoerliPriceOracleContractAddress, GoerliStartBlock, true return GoerliPostageStampContractAddress, GoerliStartBlock, true
} }
return common.Address{}, common.Address{}, 0, false return common.Address{}, 0, false
} }
...@@ -23,7 +23,6 @@ var hash common.Hash = common.HexToHash("ff6ec1ed9250a6952fabac07c6eb103550dc651 ...@@ -23,7 +23,6 @@ var hash common.Hash = common.HexToHash("ff6ec1ed9250a6952fabac07c6eb103550dc651
var addr common.Address = common.HexToAddress("abcdef") var addr common.Address = common.HexToAddress("abcdef")
var postageStampAddress common.Address = common.HexToAddress("eeee") var postageStampAddress common.Address = common.HexToAddress("eeee")
var priceOracleAddress common.Address = common.HexToAddress("eeef")
func TestListener(t *testing.T) { func TestListener(t *testing.T) {
logger := logging.New(ioutil.Discard, 0) logger := logging.New(ioutil.Discard, 0)
...@@ -46,7 +45,7 @@ func TestListener(t *testing.T) { ...@@ -46,7 +45,7 @@ func TestListener(t *testing.T) {
c.toLog(496), c.toLog(496),
), ),
) )
l := listener.New(logger, mf, postageStampAddress, priceOracleAddress, 1) l := listener.New(logger, mf, postageStampAddress, 1)
l.Listen(0, ev) l.Listen(0, ev)
select { select {
...@@ -77,7 +76,7 @@ func TestListener(t *testing.T) { ...@@ -77,7 +76,7 @@ func TestListener(t *testing.T) {
topup.toLog(496), topup.toLog(496),
), ),
) )
l := listener.New(logger, mf, postageStampAddress, priceOracleAddress, 1) l := listener.New(logger, mf, postageStampAddress, 1)
l.Listen(0, ev) l.Listen(0, ev)
select { select {
...@@ -108,7 +107,7 @@ func TestListener(t *testing.T) { ...@@ -108,7 +107,7 @@ func TestListener(t *testing.T) {
depthIncrease.toLog(496), depthIncrease.toLog(496),
), ),
) )
l := listener.New(logger, mf, postageStampAddress, priceOracleAddress, 1) l := listener.New(logger, mf, postageStampAddress, 1)
l.Listen(0, ev) l.Listen(0, ev)
select { select {
...@@ -137,7 +136,7 @@ func TestListener(t *testing.T) { ...@@ -137,7 +136,7 @@ func TestListener(t *testing.T) {
priceUpdate.toLog(496), priceUpdate.toLog(496),
), ),
) )
l := listener.New(logger, mf, postageStampAddress, priceOracleAddress, 1) l := listener.New(logger, mf, postageStampAddress, 1)
l.Listen(0, ev) l.Listen(0, ev)
select { select {
case e := <-evC: case e := <-evC:
...@@ -189,7 +188,7 @@ func TestListener(t *testing.T) { ...@@ -189,7 +188,7 @@ func TestListener(t *testing.T) {
), ),
WithBlockNumber(blockNumber), WithBlockNumber(blockNumber),
) )
l := listener.New(logger, mf, postageStampAddress, priceOracleAddress, 1) l := listener.New(logger, mf, postageStampAddress, 1)
l.Listen(0, ev) l.Listen(0, ev)
select { select {
...@@ -243,6 +242,13 @@ func TestListener(t *testing.T) { ...@@ -243,6 +242,13 @@ func TestListener(t *testing.T) {
case <-time.After(timeout): case <-time.After(timeout):
t.Fatal("timed out waiting for event") t.Fatal("timed out waiting for event")
} }
select {
case e := <-evC:
e.(blockNumberCall).compare(t, blockNumber-uint64(listener.TailSize)) // event args should be equal
case <-time.After(timeout):
t.Fatal("timed out waiting for block number update")
}
}) })
} }
...@@ -465,7 +471,7 @@ func (p priceArgs) compare(t *testing.T, want priceArgs) { ...@@ -465,7 +471,7 @@ func (p priceArgs) compare(t *testing.T, want priceArgs) {
} }
func (p priceArgs) toLog(blockNumber uint64) types.Log { func (p priceArgs) toLog(blockNumber uint64) types.Log {
b, err := listener.PriceOracleABI.Events["PriceUpdate"].Inputs.NonIndexed().Pack(p.price) b, err := listener.PostageStampABI.Events["PriceUpdate"].Inputs.NonIndexed().Pack(p.price)
if err != nil { if err != nil {
panic(err) panic(err)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment