minetest-mods / technic

Technic mod for Minetest
Other
145 stars 155 forks source link

Power Doubling Bug #277

Open asl97 opened 8 years ago

asl97 commented 8 years ago

It's hard for me to clearly explain in words on how to reproduce it so I will just post a whole bunch of pictures.

It is possible to abuse this to generate six times as much energy. For example, using the nuclear generator, that means 600000, although the alarm would be ringing and it would melt down.

screenshot_2016-04-22_21-02-34 the first energy update seem to have some kind of race condition or something... screenshot_2016-04-22_21-02-41 screenshot_2016-04-22_21-02-52 screenshot_2016-04-22_21-03-00 screenshot_2016-04-22_21-03-08 screenshot_2016-04-22_21-03-17 last image in another angle, to clearly show how to build it. screenshot_2016-04-22_21-03-49


Note: bug is NOT fix by https://github.com/minetest-mods/technic/commit/33455328bd4fbfacd26e3f02b77f2b54bea982d9 See https://github.com/minetest-mods/technic/issues/277#issuecomment-293822014

Ekdohibs commented 8 years ago

Explanation of why it doubles power: The two switching stations run independent networks, and each of them get the same amount of energy from the solar panel and put it in the battery box. Now, the question is how to fix this: it means that a generator has to check it is not connected to several different networks; likewise, a consumer should check the same thing. This is non-trivial, though.

pyrollo commented 8 years ago

Shouldn't it be sufficient to add all Producer and Receiver nodes to all_nodes table in function check_node_subp of switching_station.lua ?

numberZero commented 8 years ago

add all Producer and Receiver nodes to all_nodes table It seems that that would have a side-effect: machine would work as a cable.

Instead, machine should keep its network ID so that the SW can check should it run that machine.

HybridDog commented 7 years ago

The machines should all have an internal capacitor. The gametime at the time of the last access is stored in meta and when accessing the machine, the energy it produced over time is sent all at once. Giving battery boxes a limited band width (and adding a capacitor node to compensate) is too intricate because of sudden glitches after entering a chunk which wasn't loaded for a long time. The decision whether battery boxes gain evenly spread amount of energy or one gets all until it's full can be made by the switching station. When multiple switching stations are connected to one network, the older ones should become inactive.

VanessaE commented 7 years ago

@HybridDog's comments notwithstanding, is this still a problem?

VanessaE commented 7 years ago

This should be fixed now, now that batteries will only draw from the bottom (like they were supposed to)

asl97 commented 7 years ago

@VanessaE The problem ain't the battery lol. Just because we can no longer gather the power from the different network into one point doesn't mean we can't power stuff directly off each of the network

If people really want to gather them together, they can use the power converter as proxy.


Screenshots of five compressor powering off one lv array solar

used power: 300 x 5 = 1500 power supply: 500

screenshot_20170413_162843 screenshot_20170413_162849

VanessaE commented 7 years ago

obviously there's more work to do :stuck_out_tongue:

numberZero commented 7 years ago

One possible workaround: #313 Another one: make machines connect from one direction only. Actually that is only needed for generators not consuming fuel (and supply convertors), as for fuel-consuming generators increased power output implies increased fuel consumption, and for other machines increased speed implies increased power consumption, so that’s not that problematic and may even be considered a feature.

By the way, there is at least one legitimate use for connecting a battery box from several sides simultaneously: this way it works as a shield between two networks, protecting each from overload in another one.

VanessaE commented 7 years ago

In the original implementation of this mod, machines only connected from the bottom (except for the supply converter).

I like your idea of making all power-producing nodes only connect from the bottom; indeed there's zero reason to allow all-sides from something thin like a solar panel.

Desour commented 7 years ago

About the solar panel: It would be very nice if they would behave to each other as cable. So you could make plates of solar panels. But this should be limited, so we could add some connected solar array structure. But for sure the connection to sides makes no sense.

Only one connecting side to cables with all machines would be very inconvenient.

It could be good if only suppliers behave as cable but not demanders.

HybridDog commented 7 years ago

As l already tried to suggest (https://github.com/minetest-mods/technic/issues/277#issuecomment-284513625), if you change the machine functions by passing network info and individual dtime, the dtime would be 0 (nearly), the solar panel multiplies its output with dtime and so it doesn't make additional power. There'd be network nodes' polling, the passed network info is a table containing the available power, etc., and the passed dtime is the gametime difference between the current and previous poll (stored in meta). The producing nodes need to give power that consuming nodes can use it, thus there need to be different flags:

Machines can have multiple flags, e.g. consumer and secondary_producer for supply converter and battery box.

numberZero commented 7 years ago

@HybridDog that’s overcomplicated IMO. Just imagine how would these capacitors exchange energy all the time. If you want to write something complex, make it load all the networks in memory and process independently from ABMs, chunk loading, etc.; that complexity would be useful at least.

HybridDog commented 7 years ago

numberZero, my changes already reduce meta usage. Currently the amount of power machines produce is stored in meta.

numberZero commented 7 years ago

@HybridDog maybe I misunderstood you. Actually the meta is used already for so-called punching, that’s really ugly, but your suggestion may make that of more use. Still, my suggestion https://github.com/minetest-mods/technic/issues/277#issuecomment-213726588 is simpler IMO. See also #351, it’s not directly related but some things become trivial when you work with RAM instead of meta.

HybridDog commented 7 years ago

lf l understand it correctly, currently the power demand, production, activity etc. are stored in meta. In my suggestion only the time of last access is saved in meta (or ram) (and machine specific information, e.g. furnace inventories). l assume the complicated part may be keeping compatibility with old machines.

Ekdohibs commented 7 years ago

I am currently rewriting the whole technic power distribution system, both to make it more efficient and to fix these kinds of bugs, so this bug will probably be fixed when this is done.

numberZero commented 7 years ago

@HybridDog well, if you store that in RAM, meta is not updated each second, that’s what is important. But IMO it’s difficult to make such system reliable as it has to work with fractions (that is, floats). What if input and output are matched exactly, and there is no batbox in the network? (e.g. 2 HV solar panels connected to a supply converter).

On the other hand, this way the system may not need to be updated each second; instead, calculations may be done only when necessary (i.e. when something changes, or a player tries to look into, etc.) So... if you can do that reliably, that would be very good. Although as @Ekdohibs rewrites exactly that code, you probably need to cooperate in some way.

HybridDog commented 7 years ago

[Meta updating each second] is important.

It isn't, l'm suggesting to not use meta for technic related information in the machine definitions (it may still be used for inventory etc.). The machines' technic functions get a table with information as parameter and can use and change those informations (e.g. available power in the network). So the last access to a machine can easily be cached.

What if input and output are matched exactly, and there is no batbox in the network? (e.g. 2 HV solar panels connected to a supply converter).

The HV solar panels request a polling interval of 1 second (because time of day changes). The switching station polls the network.

The target network can also ask the supply converter to poll the network with the solar panels.

numberZero commented 7 years ago

[Meta updating each second] is important.

@rubenwardy, now you seem to misunderstood me. I meant that not to update meta each second is important: that reduces disk and network usage greatly.

And just a question: are you aware of floats’ imprecise nature? Or you plan to work with integers only? The error is (usually) tiny, but if you had an exact match, as in my example (BTW, I meant old-style SC consuming exactly 10 kPU), you may and often will lose it.

HybridDog commented 7 years ago

exact matches are very unrealistic. In your example you maybe would never loose it because due to server lag, the update step would be >= 1 second. And you could add a capacitor functionality to the SC.