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 (
optionNameTransactionHash = "transaction"
optionNameFullNode = "full-node"
optionNamePostageContractAddress = "postage-stamp-address"
optionNamePriceOracleAddress = "price-oracle-address"
optionNameBlockTime = "block-time"
)
......@@ -233,7 +232,6 @@ func (c *command) setAllFlags(cmd *cobra.Command) {
cmd.Flags().Bool(optionNameSwapEnable, true, "enable swap")
cmd.Flags().Bool(optionNameFullNode, false, "cause the node to start in full mode")
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().Uint64(optionNameBlockTime, 15, "chain block time")
}
......
......@@ -152,7 +152,6 @@ Welcome to the Swarm.... Bzzz Bzzzz Bzzzz
FullNodeMode: fullNode,
Transaction: c.config.GetString(optionNameTransactionHash),
PostageContractAddress: c.config.GetString(optionNamePostageContractAddress),
PriceOracleAddress: c.config.GetString(optionNamePriceOracleAddress),
BlockTime: c.config.GetUint64(optionNameBlockTime),
})
if err != nil {
......
......@@ -8,7 +8,7 @@ require (
github.com/coreos/go-semver v0.3.0
github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c // indirect
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/langos v1.0.0
github.com/gogo/protobuf v1.3.1
......
......@@ -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/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/ethersphere/go-storage-incentives-abi v0.1.0 h1:yxNME3q5dha/pUtIYB07DALhhQjd3+uYhGLFqKMXVyg=
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 h1:TZ15auzGsdzuzUR2b5dLAMpFixorb4uKUDGF0QnVmmU=
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/go.mod h1:BmpsvJ8idQZdYEtWnvxA8POYQ8Rl/NhyCdF0zLMOOJU=
github.com/ethersphere/langos v1.0.0 h1:NBtNKzXTTRSue95uOlzPN4py7Aofs0xWPzyj4AI1Vcc=
......
......@@ -346,27 +346,20 @@ func NewBee(addr string, swarmAddress swarm.Address, publicKey ecdsa.PublicKey,
var postageSyncStart uint64 = 0
if !o.Standalone {
postageContractAddress, priceOracleAddress, startBlock, found := listener.DiscoverAddresses(chainID)
postageContractAddress, startBlock, found := listener.DiscoverAddresses(chainID)
if o.PostageContractAddress != "" {
if !common.IsHexAddress(o.PostageContractAddress) {
return nil, errors.New("malformed postage stamp address")
}
postageContractAddress = common.HexToAddress(o.PostageContractAddress)
}
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 {
} else if !found {
return nil, errors.New("no known postage stamp addresses for this network")
}
if found {
postageSyncStart = startBlock
}
eventListener := listener.New(logger, swapBackend, postageContractAddress, priceOracleAddress, o.BlockTime)
eventListener := listener.New(logger, swapBackend, postageContractAddress, o.BlockTime)
b.listenerCloser = eventListener
batchSvc = batchservice.New(batchStore, logger, eventListener)
......
......@@ -6,7 +6,6 @@ package listener
var (
PostageStampABI = postageStampABI
PriceOracleABI = priceOracleABI
BatchCreatedTopic = batchCreatedTopic
BatchTopupTopic = batchTopupTopic
......
......@@ -30,16 +30,15 @@ const (
)
var (
postageStampABI = parseABI(postageabi.PostageStampABIv0_1_0)
priceOracleABI = parseABI(postageabi.PriceOracleABIv0_1_0)
postageStampABI = parseABI(postageabi.PostageStampABIv0_2_0)
// batchCreatedTopic is the postage contract's batch created event topic
batchCreatedTopic = postageStampABI.Events["BatchCreated"].ID
// batchTopupTopic is the postage contract's batch topup event topic
batchTopupTopic = postageStampABI.Events["BatchTopUp"].ID
// batchDepthIncreaseTopic is the postage contract's batch dilution event topic
batchDepthIncreaseTopic = postageStampABI.Events["BatchDepthIncrease"].ID
// priceUpdateTopic is the price oracle's price update event topic
priceUpdateTopic = priceOracleABI.Events["PriceUpdate"].ID
// priceUpdateTopic is the postage contract's price update event topic
priceUpdateTopic = postageStampABI.Events["PriceUpdate"].ID
)
type BlockHeightContractFilterer interface {
......@@ -53,7 +52,6 @@ type listener struct {
blockTime uint64
postageStampAddress common.Address
priceOracleAddress common.Address
quit chan struct{}
wg sync.WaitGroup
}
......@@ -61,17 +59,14 @@ type listener struct {
func New(
logger logging.Logger,
ev BlockHeightContractFilterer,
postageStampAddress,
priceOracleAddress common.Address,
postageStampAddress common.Address,
blockTime uint64,
) postage.Listener {
return &listener{
logger: logger,
ev: ev,
blockTime: blockTime,
logger: logger,
ev: ev,
blockTime: blockTime,
postageStampAddress: postageStampAddress,
priceOracleAddress: priceOracleAddress,
quit: make(chan struct{}),
}
}
......@@ -82,7 +77,6 @@ func (l *listener) filterQuery(from, to *big.Int) ethereum.FilterQuery {
ToBlock: to,
Addresses: []common.Address{
l.postageStampAddress,
l.priceOracleAddress,
},
Topics: [][]common.Hash{
{
......@@ -132,7 +126,7 @@ func (l *listener) processEvent(e types.Log, updater postage.EventUpdater) error
)
case priceUpdateTopic:
c := &priceUpdateEvent{}
err := transaction.ParseEvent(&priceOracleABI, "PriceUpdate", c, e)
err := transaction.ParseEvent(&postageStampABI, "PriceUpdate", c, e)
if err != nil {
return err
}
......@@ -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
}
}
......@@ -274,16 +273,15 @@ type priceUpdateEvent struct {
}
var (
GoerliPostageStampContractAddress = common.HexToAddress("0xF7a041E7e2B79ccA1975852Eb6D4c6cE52986b4a")
GoerliPriceOracleContractAddress = common.HexToAddress("0x1044534090de6f4014ece6d036C699130Bd5Df43")
GoerliStartBlock = uint64(4247101)
GoerliPostageStampContractAddress = common.HexToAddress("0xB3B7f2eD97B735893316aEeA849235de5e8972a2")
GoerliStartBlock = uint64(4818979)
)
// 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 {
// 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
var addr common.Address = common.HexToAddress("abcdef")
var postageStampAddress common.Address = common.HexToAddress("eeee")
var priceOracleAddress common.Address = common.HexToAddress("eeef")
func TestListener(t *testing.T) {
logger := logging.New(ioutil.Discard, 0)
......@@ -46,7 +45,7 @@ func TestListener(t *testing.T) {
c.toLog(496),
),
)
l := listener.New(logger, mf, postageStampAddress, priceOracleAddress, 1)
l := listener.New(logger, mf, postageStampAddress, 1)
l.Listen(0, ev)
select {
......@@ -77,7 +76,7 @@ func TestListener(t *testing.T) {
topup.toLog(496),
),
)
l := listener.New(logger, mf, postageStampAddress, priceOracleAddress, 1)
l := listener.New(logger, mf, postageStampAddress, 1)
l.Listen(0, ev)
select {
......@@ -108,7 +107,7 @@ func TestListener(t *testing.T) {
depthIncrease.toLog(496),
),
)
l := listener.New(logger, mf, postageStampAddress, priceOracleAddress, 1)
l := listener.New(logger, mf, postageStampAddress, 1)
l.Listen(0, ev)
select {
......@@ -137,7 +136,7 @@ func TestListener(t *testing.T) {
priceUpdate.toLog(496),
),
)
l := listener.New(logger, mf, postageStampAddress, priceOracleAddress, 1)
l := listener.New(logger, mf, postageStampAddress, 1)
l.Listen(0, ev)
select {
case e := <-evC:
......@@ -189,7 +188,7 @@ func TestListener(t *testing.T) {
),
WithBlockNumber(blockNumber),
)
l := listener.New(logger, mf, postageStampAddress, priceOracleAddress, 1)
l := listener.New(logger, mf, postageStampAddress, 1)
l.Listen(0, ev)
select {
......@@ -243,6 +242,13 @@ func TestListener(t *testing.T) {
case <-time.After(timeout):
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) {
}
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 {
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